Toggle Navigation
Hatchery
Eggs
Schnick Schnack Schnuck
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import os import display import bhi160 import math import buttons def main(): disp = display.open() options = ["Schere", "Stein", "Papier"] axel = bhi160.BHI160Accelerometer() threshold = 1.9 schnuck = "Schnick Schnack Shake It" while True: disp.clear() samples = axel.read() if len(samples) > 0: sample = samples[0] x = abs(sample.x) y = abs(sample.y) z = abs(sample.z) value = x + y + z if (value > threshold): schnuck = options[math.floor((value * 100)%len(options))] # Read button v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) if v == 0: button_pressed = False if not button_pressed and v & buttons.BOTTOM_LEFT != 0: button_pressed = True threshold = max(threshold - 0.1, 0.1) if not button_pressed and v & buttons.BOTTOM_RIGHT != 0: button_pressed = True threshold = threshold + 0.1 disp.print(schnuck, posy=20) disp.print("Threshold: %f" % threshold, posy=40) disp.update() if __name__ == "__main__": main()