Toggle Navigation
Hatchery
Eggs
Decision
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
""" Decision ======== """ import buttons import color import display import os import leds import utime import vibra def button_events(): """Iterate over button presses (event-loop).""" yield 0 button_pressed = False while True: v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT) if v == 0: button_pressed = False if not button_pressed and v & buttons.BOTTOM_LEFT != 0: button_pressed = True yield buttons.BOTTOM_LEFT if not button_pressed and v & buttons.BOTTOM_RIGHT != 0: button_pressed = True yield buttons.BOTTOM_RIGHT if not button_pressed and v & buttons.TOP_RIGHT != 0: button_pressed = True yield buttons.TOP_RIGHT def ueberlegen(disp): disp.clear() disp.print("Lass mich kurz ueberlegen...", fg=[0, 0, 0],bg=[255,255,255], posx=0, posy=0) disp.update() utime.sleep_ms(3000) def leds_yes(): for x in range(0,4): for led in range(0,14): leds.set(led, [0,255,0]) utime.sleep_ms(700) for led in range(0,14): leds.set(led, [0,0,0]) utime.sleep_ms(200) def leds_no(): for led in range(0,14): leds.set(led, [255,0,0]) def main(): disp = display.open() disp.clear() disp.print("Decision?", fg=[0, 0, 0],bg=[255,255,255], posx=20, posy=30) disp.update() for ev in button_events(): if ev == buttons.BOTTOM_RIGHT: ueberlegen(disp) disp.clear() disp.print("Ja", fg=[0, 0, 0], bg=[255,255,255], posx=60, posy=30) disp.update() leds_yes() elif ev == buttons.BOTTOM_LEFT: ueberlegen(disp) disp.clear() disp.print("Nein", fg=[0, 0, 0], bg=[255,255,255], posx=40, posy=30) leds_no() vibra.vibrate(1000) elif ev == buttons.TOP_RIGHT: ueberlegen(disp) disp.clear() disp.print("Vielleicht", fg=[0, 0, 0], bg=[255,255,255], posx=10, posy=30) disp.update() utime.sleep_ms(3000) disp.clear() disp.update() for led in range(0,14): leds.set(led, [0,0,0]) if __name__ == "__main__": main()