pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Bugc2

Example

Alternates between moving forward and backward.

from m5stack import *
from m5ui import *
from uiflow import *
import time
import hat

setScreenColor(0x111111)

hat_bugc2_0 = hat.get(hat.BUGC2)

hat_bugc2_0.InitDeviceAddr(0x38)
while True:
  hat_bugc2_0.SetMotorSpeed(0x00, 100)
  hat_bugc2_0.SetMotorSpeed(0x02, 100)
  hat_bugc2_0.SetMotorSpeed(0x01, -100)
  hat_bugc2_0.SetMotorSpeed(0x03, -100)
  wait(5)
  hat_bugc2_0.SetMotorSpeed(0x00, -100)
  hat_bugc2_0.SetMotorSpeed(0x02, -100)
  hat_bugc2_0.SetMotorSpeed(0x01, 100)
  hat_bugc2_0.SetMotorSpeed(0x03, 100)
  wait(5)
  wait_ms(2)

API

hat_bugc2_0.InitDeviceAddr(0x38)
  • Initialize the device I2C address, set to 0x38.
hat_bugc2_0.GetAdcValue(8)
  • Get the raw 8-bit ADC value (returns an integer).
hat_bugc2_0.GetBatVoltage
  • Get the battery voltage in millivolts (returns an integer).
hat_bugc2_0.GetDeviceSpec(0xFE)
  • Retrieve detailed firmware version information (returns an integer).
hat_bugc2_0.SetRxCb(hat_bugc2_0_rx_cb)
  • NEC infrared reception callback function, used to process received data and address.
hat_bugc2_0.SetI2cAddress(0x38)
  • Set the I2C address of the device.
hat_bugc2_0.SetMotorSpeed(0x00, 50)
  • Set the speed of the front-left motor. The current speed is set to 50, with a range of -100 to 100.
hat_bugc2_0.SetRGBColor(0x00, 0xff0000)
  • Set the RGB color of the wheel lights, currently set to red.
On This Page