pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

8Servo V1.1

控制多个舵机循环每隔一秒转动一个角度,你可以继续添加舵机数量

案例程序

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:
  .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)

功能说明

hat_8servos_1.get_pwr_ctrl()
  • 获取舵机电源控制状态
hat_8servos_1.read_servo_angle(1)
  • 读取指定通道的舵机角度
hat_8servos_1.read_servo_pulse(1)
  • 读取指定通道的舵机脉冲
hat_8servos_1.set_pwr_ctrl(1)
  • 设置舵机的电源控制
hat_8servos_1.write_servo_angle(1,0)
  • 设置指定通道的舵机角度
hat_8servos_1.write_servo_pulse(1,500)
  • 设置指定通道的舵机脉冲
On This Page