pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

PbHUB

案例程序

控制电机旋转

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

setScreenColor(0x222222)
pbhub_0 = unit.get(unit.PBHUB, unit.PORTA)

while True:
  pbhub_0.setServoAngle(0, 0, 11)
  wait(1)
  pbhub_0.setServoAngle(0, 0, 180)
  wait(1)
  wait_ms(2)

功能说明

pbhub_0.init_i2c_address(0x61)
  • 初始化I2C地址
print(pbhub_0.analogRead(0))
  • 读取模拟值
print(pbhub_0.digitalRead(0, 0))
  • 读取引脚数字值
pbhub_0.digitalWrite(0, 0, 0)
  • 向引脚写入数字值
print(pbhub_0.pwmRead(0, 0))
  • 读取对应引脚对应脉冲
pbhub_0.pwmWrite(0, 0, 0)
  • 向对应引脚下对应IO口写入脉冲
print(pbhub_0.read_status(0xFE))
  • 读取 unit 状态/版本号
pbhub_0.setBrightness(0, 50)
  • 设置指定引脚RGB灯珠亮度
pbhub_0.setColorPos(0, 0, 0xff0000)
  • 设置指定引脚对应指定序号RGB灯珠的颜色
pbhub_0.setColorPos(0, 0, 0xff0000)
  • 设置指定引脚对应指定范围RGB灯珠的颜色(可选择RGB方式palette/Rgb/Hex)
pbhub_0.setColor(0, 0, 0, 0xff0000)
  • 设置指定引脚对应指定范围RGB灯珠的颜色
pbhub_0.setColor(0, 0, 0, 0xff0000)
  • 设置指定范围内RGB灯珠颜色(可选择RGB方式palette/Rgb/Hex)
pbhub_0.setRgbNum(0, 1)
  • 设置指定引脚IO口的LED灯
pbhub_0.init_i2c_address(0x61)
  • 设置固件版本/I2C地址
pbhub_0.setServoAngle(0, 0, 90)
  • 设置舵机旋转的角度
pbhub_0.setServoPulse(0, 0, 1000)
  • 向引脚写入数字值
On This Page