micropython陀螺仪控制舵机

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-21 13:04   22   0

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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP