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

disp = display.open()

7
8
bhi = bhi160.BHI160Accelerometer()

koalo's avatar
koalo committed
9
while True:
10
11
12
13
    samples = bhi.read()
    if len(samples) > 0:
        disp.clear()
        sample = samples[0]
koalo's avatar
koalo committed
14

koalo's avatar
koalo committed
15
16
17
18
19
20
21
22
        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]

23
        disp.print("Accelerometer", posy=0)
koalo's avatar
koalo committed
24
25
26
        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
27

28
        disp.update()
koalo's avatar
koalo committed
29

30
    utime.sleep(0.1)