pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

8Servo V1.1

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

Example

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.
On This Page