from machine import PWM, Pin
import utime servoLU = PWM(Pin(12)) #左上 servoLD = PWM(Pin(13)) #左下 servoRU = PWM(Pin(14)) #右上 servoRD = PWM(Pin(15)) #右下 servoLU.freq(50) servoLD.freq(50) servoRU.freq(50) servoRD.freq(50) def servo_value(degree): return int((degree * 9.5 / 180 + 2.5) * 65535 / 100) servoLU.duty_u16(servo_value(90)) servoLD.duty_u16(servo_value(180)) servoRU.duty_u16(servo_value(0)) servoRD.duty_u16(servo_value(0)) #歩行速度 WALKING_SPEED = 1; while True: #右足 servoRD.duty_u16(servo_value(20)) utime.sleep(1) servoRU.duty_u16(servo_value(20)) utime.sleep(WALKING_SPEED) servoRD.duty_u16(servo_value(0)) utime.sleep(1) servoRU.duty_u16(servo_value(0)) utime.sleep(WALKING_SPEED) #左足 servoLD.duty_u16(servo_value(160)) utime.sleep(1) servoLU.duty_u16(servo_value(60)) utime.sleep(WALKING_SPEED) servoLD.duty_u16(servo_value(180)) utime.sleep(1) servoLU.duty_u16(servo_value(90)) utime.sleep(WALKING_SPEED) |