pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Module 2Relay

案例程序

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)

功能说明

import module
relay2 = module.get(module.RELAY2)
relay2.init_i2c_address(0x25)
  • 初始化模组, 同时指定I2C地址(默认为0x25)
print(relay2.read_status(0xFE))
  • 获取设备固件版本信息
relay2.write_relay_state(1, 1)
  • 设置继电器状态:
    • relay: 1-2
    • state:
      • on:1
      • off:0
print(relay2.read_relay_status(1))
  • 读取继电器状态:
    • relay: 1-2
  • 返回值
    • state:
      • on:1
      • off:0
relay2.write_i2c_address(0x25)
  • 设置模块I2C地址
On This Page