pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Module 2Relay

Example

from m5stack import *
from m5ui import *
from uiflow import *
import module

import time

setScreenColor(0x000000)
relay2 = module.get(module.RELAY2)

relay2.init_i2c_address(0x25)
print((str('DEVICE VER:') + str((relay2.read_status(0xFE)))))
print((str('DEVICE I2C:') + str((relay2.read_status(0xFF)))))
while True:
  relay2.write_relay_state(1, 0)
  relay2.write_relay_state(2, 0)
  wait(1)
  relay2.write_relay_state(1, 1)
  relay2.write_relay_state(2, 1)
  wait(1)
  wait_ms(2)

API

import module
relay2 = module.get(module.RELAY2)
relay2.init_i2c_address(0x25)
  • Initialize the module and specify the I2C address (default is 0x25).
print(relay2.read_status(0xFE))
  • Get device firmware version information
relay2.write_relay_state(1, 1)
  • Setting Relay Status:
    • relay: 1-2
    • state:
      • on:1
      • off:0
print(relay2.read_relay_status(1))
  • Read relay status:
    • relay: 1-2
  • return
    • state:
      • on:1
      • off:0
relay2.write_i2c_address(0x25)
  • Setting the module I2C address
On This Page