pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Servo

Example

Rotates the servo to different positions every second.

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

setScreenColor(0x111111)

hat_servo_0 = hat.get(hat.SERVO)

while True:
  hat_servo_0.write_angle(0)
  wait(1)
  hat_servo_0.write_angle(90)
  wait(1)
  hat_servo_0.write_angle(180)
  wait(1)
  wait_ms(2)

API

hat_servo_0.write_angle(0)
  • This block sets the servo to a specified angle (in degrees). In this example, it’s set to 0 degrees.
hat_servo_0.write_us(600)
  • This block writes a pulse width directly to the servo in microseconds. In this example, it’s set to a 600-microsecond pulse width.
On This Page