English
English
简体中文
日本語

UiFlow Tutorial

UiFlow1 Development Guide

Project Management

Use LTE network

UiFlow1 Blockly

Event

Unit

Hat 8Servo V1.1

Example

Control multiple servos to rotate at specific angles every second in a loop. You can continue to add more servos if needed.

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

setScreenColor(0x111111)

hat_servos_1 = hat.get(hat.SERVOS)

hat_8servos_2.set_pwr_ctrl(1)
while True:
  hat_8servos_2.write_servo_angle(1,0)
  hat_8servos_2.write_servo_angle(2,0)
  hat_8servos_2.write_servo_angle(3,0)
  hat_8servos_2.write_servo_angle(4,0)
  wait(1)
  hat_8servos_2.write_servo_angle(1,90)
  hat_8servos_2.write_servo_angle(2,90)
  hat_8servos_2.write_servo_angle(3,90)
  hat_8servos_2.write_servo_angle(4,90)
  wait(1)
  hat_8servos_2.write_servo_angle(1,180)
  hat_8servos_2.write_servo_angle(2,180)
  hat_8servos_2.write_servo_angle(3,180)
  hat_8servos_2.write_servo_angle(4,180)
  wait(1)
  hat_8servos_2.write_servo_angle(1,90)
  hat_8servos_2.write_servo_angle(2,90)
  hat_8servos_2.write_servo_angle(3,90)
  hat_8servos_2.write_servo_angle(4,90)
  wait(1)
  hat_8servos_2.write_servo_angle(1,0)
  hat_8servos_2.write_servo_angle(2,0)
  hat_8servos_2.write_servo_angle(3,0)
  hat_8servos_2.write_servo_angle(4,0)
  wait(1)
  wait_ms(2)

API

hat_8servos_1.get_pwr_ctrl()
  • Get the power control status of the servos.
hat_8servos_1.read_servo_angle(1)
  • Read the angle of the specified servo channel.
hat_8servos_1.read_servo_pulse(1)
  • Read the pulse width of the specified servo channel.
hat_8servos_1.set_pwr_ctrl(1)
  • Set the power control for the servos.
hat_8servos_1.write_servo_angle(1,0)
  • Set the angle of the specified servo channel.
hat_8servos_1.write_servo_pulse(1,500)
  • Set the pulse width of the specified servo channel.
Page Tools
PDF
On This Page