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()

@青山不移,文笔不息。学习,坚持,梦想青春!
原文地址:https://www.cnblogs.com/pengwenzheng/p/8551580.html