pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

UNit Acssr

案例程序

from m5stack import *
from m5ui import *
from uiflow import *
import unit

setScreenColor(0x222222)
acssr_0 = unit.get(unit.AC_SSR, unit.PORTA)

def buttonA_wasPressed():
  # global params
  acssr_0.set_i2c_ssr_state(1)
  pass
btnA.wasPressed(buttonA_wasPressed)

def buttonB_wasPressed():
  # global params
  acssr_0.set_i2c_ssr_state(0)
  pass
btnB.wasPressed(buttonB_wasPressed)

def buttonC_wasPressed():
  # global params
  acssr_0.set_i2c_rgb_led(50, 50, 50)
  pass
btnC.wasPressed(buttonC_wasPressed)

acssr_0.init_mode(1)
print((str('FW version:') + str((acssr_0.get_i2c_status(0xFE)))))
while True:
  if acssr_0.get_i2c_ssr_status():
    print('ON')
  else:
    print('OFF')
  wait_ms(2)

功能说明

acssr_0.init_i2c_address(0x50)
  • 初始化设置ACSSR Unit 的I2C通讯地址
acssr_0.init_modbus(4, 1, 115200, 8, 1, None)
  • 初始化Modbus通讯格式
print(acssr_0.get_i2c_rgb_led())
  • 通过i2c获取RGB的值
print(acssr_0.get_i2c_ssr_status())
  • 通过I2C获取SSR的开关状态
print(acssr_0.get_i2c_status(0xFE))
  • 通过I2C模式获取固件版本
print(acssr_0.get_modbus_rgb_led())
  • 通过Modbus通讯方式获取RGB的值
print(acssr_0.get_modbus_ssr_status())
  • 通过Modbus获取SSR的开关状态
print(acssr_0.get_modbus_status(0x0001))
  • 通过Modbus模式获取固件版本
acssr_0.init_mode(1)
  • 设置ACSSR Unit 的通讯模式,I2C或者是Modbus
acssr_0.set_i2c_address(0x50)
  • 设置ACSSR的i2c地址
acssr_0.set_i2c_rgb_led(50, 50, 50)
  • 通过i2c设置RGB值
acssr_0.set_i2c_ssr_state(1)
  • 设置SSR设备的开关状态
acssr_0.set_modbus_address(0x50)
  • 设置ACSSR的i2c地址
acssr_0.set_modbus_rgb_led(50, 50, 50)
  • Modbus设置LED的RGB值
acssr_0.set_modbus_ssr_state(1)
  • Modbus设置SSR的状态开关
On This Page