__init__.py 1.25 KB
Newer Older
koalo's avatar
koalo committed
1
2
3
import bhi160
import display
import utime
4
import buttons
koalo's avatar
koalo committed
5
6

disp = display.open()
7
sensor = 0
koalo's avatar
koalo committed
8

9
10
11
12
sensors = [
    {"sensor": bhi160.BHI160Orientation(), "name": "Orientation"},
    {"sensor": bhi160.BHI160Accelerometer(), "name": "Accelerometer"},
    {"sensor": bhi160.BHI160Gyroscope(), "name": "Gyroscope"},
13
    {"sensor": bhi160.BHI160Magnetometer(), "name": "Magnetometer"},
14
]
15

koalo's avatar
koalo committed
16
while True:
17
18
    # Read and print sample
    samples = sensors[sensor]["sensor"].read()
19
20
21
    if len(samples) > 0:
        disp.clear()
        sample = samples[0]
koalo's avatar
koalo committed
22

koalo's avatar
koalo committed
23
24
25
26
27
28
29
30
        color = [255, 0, 0]
        if sample.status == 1:
            color = [255, 128, 0]
        elif sample.status == 2:
            color = [255, 255, 0]
        elif sample.status == 3:
            color = [0, 200, 0]

31
        disp.print(sensors[sensor]["name"], posy=0)
koalo's avatar
koalo committed
32
33
34
        disp.print("X: %f" % sample.x, posy=20, fg=color)
        disp.print("Y: %f" % sample.y, posy=40, fg=color)
        disp.print("Z: %f" % sample.z, posy=60, fg=color)
koalo's avatar
koalo committed
35

36
        disp.update()
koalo's avatar
koalo committed
37

38
39
40
41
42
43
44
45
46
    # Read button
    v = buttons.read(buttons.BOTTOM_RIGHT)
    if v == 0:
        button_pressed = False

    if not button_pressed and v & buttons.BOTTOM_RIGHT != 0:
        button_pressed = True
        sensor = (sensor + 1) % len(sensors)

47
    utime.sleep(0.1)