from machine import Pin,PWM
import time
#定义舵机的对象
sensor = Pin(13,Pin.IN,Pin.PULL_UP)
S1 = PWM(Pin(19),freq=50,duty=0)
S2 = PWM(Pin(18),freq=50,duty=0)
S3 = PWM(Pin(5),freq=50,duty=0)
S4 = PWM(Pin(17),freq=50,duty=0)
def Servo(servo,angle):#定义舵级计算角度函数
servo.duty(int(((angle + 90)/90 + 0.5)/20*1023))
def fun(sensor):
for i in range(0,90,2):
Servo(S1,i)
Servo(S2,i)
Servo(S3,i)
Servo(S4,i)
time.sleep_ms(5)
sensor.irq(fun,Pin.IRQ_RISING)