pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Unit Hbridge

案例程序

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

setScreenColor(0x222222)
hbridge_0 = unit.get(unit.HBRIDGE, unit.PORTA)

hbridge_0.init_i2c_address(0x20)
hbridge_0.set_8bit_pwm(127)
hbridge_0.set_16bit_pwm(32767)
hbridge_0.set_direction(1)
while True:
  print((str('Current:') + str(((str((hbridge_0.get_vin_current())) + str('A'))))))
  wait(1)
  wait_ms(2)

功能说明

hbridge_0.init_i2c_address(0x20)
  • 初始化Unit并设置I2C地址
print(hbridge_0.get_adc_value(0, 8))
  • 获得电压值分辨率
print(hbridge_0.get_vin_current())
  • 获取电压(A,Float)
print(hbridge_0.get_device_status(0xFE))
  • 获取Unit 版本
print(hbridge_0.get_driver_config(4))
  • 获取配置信息
    • DIRECTION
    • 8Bit_PWM_DUTY
    • 16Bit_PWM_DUTY
    • PWM_FREQUENCY
hbridge_0.set_16bit_pwm(32767)
  • 设置16bit 值 PWM 占空比
hbridge_0.set_8bit_pwm(127)
  • 设置8bit 值 PWM 占空比
hbridge_0.set_direction(0)
  • 设置电流方向
  • STOP
  • FORWARD
  • REVERSE
hbridge_0.set_pwm_freq(1000)
  • 设置PWM频率
On This Page