Toggle Navigation
Hatchery
Eggs
Axelerometersnek
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import display import bhi160 import utime sens = bhi160.BHI160Accelerometer() disp = display.open() q = [] # queue QLEN = 10 # enuff is enuff! def clamp(val): return -1.0 if val < -1.0 else 1.0 if val > 1.0 else val while True: utime.sleep(0.03) # 30 fps samples = sens.read() for s in samples: if len(q) == QLEN: q.pop(0) x = 160 - int((clamp(s.x) + 1.0) * 80) y = int((clamp(s.y) + 1.0) * 40) q.append((x, y)) disp.clear() for i in range(0, len(q) - 1): c = int(20 + 235 * i / (len(q) - 1)) # color disp.line(q[i][0], q[i][1], q[i + 1][0], q[i + 1][1], col = (c,c,c), size = 1) disp.update()