English
English
简体中文
日本語

UiFlow Tutorial

UiFlow1 Development Guide

Project Management

Use LTE network

UiFlow1 Blockly

Event

Unit

Unit EXT.IO2

Example

Control servo rotation and RGB LED illumination

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

setScreenColor(0x222222)
ext_io2_0 = unit.get(unit.EXT_IO2, unit.PORTA)

ext_io2_0.init_i2c_address(0x45)
ext_io2_0.set_config_mode(2, 3)
ext_io2_0.set_config_mode(1, 4)
ext_io2_0.write_rgb_led(1, 78, 74, 96)
while True:
  ext_io2_0.write_servo_angle(2, 65)
  print((str('servo angle:') + str((ext_io2_0.read_servo_angle(2)))))
  wait(1)
  ext_io2_0.write_servo_angle(2, 176)
  print((str('servo angle:') + str((ext_io2_0.read_servo_angle(2)))))
  wait(1)
  wait_ms(2)

API

ext_io2_0.init_i2c_address(0x45)
  • Initialize EXTIO2 Unit and obtain communication address
print((str('config mode:') + str((ext_io2_0.get_config_mode(0)))))
  • Obtain the current configuration mode of a specified channel
print((str('ADC 12bit:') + str((ext_io2_0.read_adc12_pin(0)))))
  • Read 12-bit ADC value from a pin
print((str('ADC 8bit:') + str((ext_io2_0.read_adc8_pin(0)))))
  • Read 8-bit ADC value from a pin
print((str('digital input:') + str((ext_io2_0.read_input_pin(0)))))
  • Read the value of an input pin
print((str('RGB LED:') + str((ext_io2_0.read_rgb_led(0)))))
  • Read the RGB LED value of a specified channel
print((str('servo angle:') + str((ext_io2_0.read_servo_angle(0)))))
  • Read the servo rotation angle of a specified channel
print((str('servo pulse:') + str((ext_io2_0.read_servo_pulse(0)))))
  • Read the pulse width of a specified channel
print((str('version:') + str((ext_io2_0.read_status(0XFE)))))
  • Obtain the current device firmware version
ext_io2_0.set_config_mode(0, 0)
  • Set the configuration mode of a specific channel
ext_io2_0.set_i2c_address(0x45)
  • Reset the I2C address
ext_io2_0.write_output_pin(0, 0)
  • Set the digital output pin level
ext_io2_0.write_rgb_led(0, 0, 0, 0)
  • Write RGB color value
ext_io2_0.write_servo_angle(0, 0)
  • Write angle
ext_io2_0.write_servo_pulse(0, 500)
  • Write pulse width
Page Tools
PDF
On This Page