micropython陀螺仪控制舵机

2018-03-1220:14:00

import pyb
import time
from pyb import Pin
xlights = (pyb.LED(2),pyb.LED(3))
MO = Pin('X1',Pin.OUT_PP)
accel = pyb.Accel()
i = 0.0001
while True:
    x = accel.x()
    print("x=")
    print(x)
    # 获取到陀螺仪x数据
    Y = x+20
    MO.high()
    time.sleep(i*Y)
    MO.low()
    time.sleep(i*Y)
    pyb.delay(12)
    if x > 0:
        xlights[0].on()
        xlights[1].off()
    elif x < 0:
        xlights[1].on()
        xlights[0].off()
    else:
        xlights[0].off()
        xlights[1].off()

micropython陀螺仪控制舵机_第1张图片

转载于:https://www.cnblogs.com/pengwenzheng/p/8551580.html

你可能感兴趣的:(micropython陀螺仪控制舵机)