English
English
简体中文
日本語

UiFlow Tutorial

UiFlow1 Development Guide

Project Management

Use LTE network

UiFlow1 Blockly

Event

Unit

Hat CBack Driver

Example

Controls two servo channels to rotate back and forth from 0 to 180 degrees.

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

setScreenColor(0x111111)

hat_cback_0 = hat.get(hat.CBACK)

while True:
  hat_cback_0.set_servo_angle(0x00, 0)
  hat_cback_0.set_servo_angle(0x01, 0)
  wait(1)
  hat_cback_0.set_servo_angle(0x00, 90)
  hat_cback_0.set_servo_angle(0x01, 90)
  wait(1)
  hat_cback_0.set_servo_angle(0x00, 180)
  hat_cback_0.set_servo_angle(0x01, 180)
  wait(1)
  hat_cback_0.set_servo_angle(0x00, 90)
  hat_cback_0.set_servo_angle(0x01, 90)
  wait(1)
  wait_ms(2)

API

hat_cback_0.set_output(0)
  • Checks the status of input port B.
hat_cback_0.get_adc16_raw()
  • Reads the raw ADC value.
hat_cback_0.set_output(0)
  • Sets the status of output port B, with possible output values of 0 or 1.
hat_cback_0.set_servo_angle(0x00, 0)
  • Sets the servo motor angle, specifying the servo channel (Channel 1 here) with an angle of 0 degrees.
hat_cback_0.set_servo_pulse(0x10, 500)
  • Sets the pulse width for the servo motor, specifying the servo channel (Channel 1 here) with a pulse width of 500.
Page Tools
PDF
On This Page