English
English
简体中文
日本語

UiFlow Tutorial

UiFlow1 Development Guide

Project Management

Use LTE network

UiFlow1 Blockly

Event

Unit

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