美文网首页
Micropython | 兔子帽子

Micropython | 兔子帽子

作者: T_K_233 | 来源:发表于2019-01-14 20:19 被阅读0次
    from pyb import Accel, Servo
    import time
    acc = Accel()
    s_l = Servo(1)
    s_r = Servo(2)
    xs = [0] * 40
    ys = [0] * 40
    while True:
        xs.pop(0)
        ys.pop(0)
        xs.append(-acc.z()*5)
        ys.append(acc.x()*6+(acc.y()-20)*12)
        x = y = 0
        for i in xs:
            x += i
        for i in ys:
            y += i
        x /= len(xs)
        y /= len(ys)
        s_l.angle(max(-120, min(120, x - y)))
        s_r.angle(max(-120, min(120, x + y)))
        time.sleep_ms(10)
    

    相关文章

      网友评论

          本文标题:Micropython | 兔子帽子

          本文链接:https://www.haomeiwen.com/subject/ijzjdqtx.html