8x8矩阵上的陀螺仪动画

时间:2019-05-03 14:44:22

标签: python raspberry-pi

因此,我一直在尝试在每架飞机上,但在我的树莓派Sense帽子上,都使用这种主要的飞行显示器。简单地说,它只是显示鼻子的what角和飞机倾斜的角度。我设法在前后倾斜Pi时使其工作(这是相当困难的编码),但我不知道如何在倾斜和倾斜Pi时使其工作。我什至不确定是否可以硬编码所有东西。

代码如下:

from sense_hat import SenseHat
import time

sense = SenseHat()

brown = [153, 76, 0]
blue = [0, 128, 255]


def neutral():
    a = b = c = d = blue
    e = f = g = h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def onedegfrwrd():
    a = b = c = blue
    d = e = f = g = h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def twodegfrwrd():
    a = b = blue
    c = d = e = f = g = h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def threedegfrwrd():
    a = blue
    b = c = d = e = f = g = h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def mcas():
    a = b = c = d = e = f = g = h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def onedegback():
    a = b = c = d = e = blue
    f = g = h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def twodegback():
    a = b = c = d = e = f = blue
    g = h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def threedegback():
    a = b = c = d = e = f = g= blue
    h = brown
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

def fullback():
    a = b = c = d = e = f = g = h = blue
    grid = [
    a, a, a, a, a, a, a, a,
    b, b, b, b, b, b, b, b,
    c, c, c, c, c, c, c, c,
    d, d, d, d, d, d, d, d,
    e, e, e, e, e, e, e, e,
    f, f, f, f, f, f, f, f,
    g, g, g, g, g, g, g, g,
    h, h, h, h, h, h, h, h
    ]
    sense.set_pixels(grid)

while True:
    orientation = sense.get_orientation_degrees()
    y = orientation['roll']
    y = round(y, 1)


    if 80 <= y <= 100:
        neutral()
        print("Stabelized")
    if 60<= y <=80:
        onedegfrwrd()
    if 40 <= y <=60:
        twodegfrwrd()
    if 20 <= y <= 40:
        threedegfrwrd()
        print("PULL UP")
    if 0 <= y <= 20:
        mcas()
        print("PULL UP")
    if 350 <= y <= 359:
        sense.clear()


    if 100 <= y <= 120:
        onedegback()
    if 120 <= y <= 140:
        twodegback()
    if 140 <= y <= 160:
        threedegback()
    if 160 <= y <= 180:
        fullback()

只要忽略我奇怪的变量名;)

0 个答案:

没有答案