Toggle Navigation
Hatchery
Eggs
Handshake
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import display import utime import leds import ujson import vibra import simple_menu import color f = open('handshakerc.json', 'r') config = ujson.loads(f.read()) f.close() def alarm(type): if type["type"] == "vibra": # { "type" : "vibra", "onofftimes" : [150, 100, 150] } vibrastate = False for vibratime in type["onofftimes"]: vibrastate = not vibrastate vibra.set(vibrastate) utime.sleep_ms(vibratime) vibra.set(False) elif type["type"] == "rocket": # { "type" : "rocket", "num" : 0 , "brightness" : 31} leds.set_rocket(type["num"], type["brightness"]) def run(at): with display.open() as disp: disp.backlight(0) start = utime.time() current = 0 alarmtimes = [] for a in at.keys(): alarmtimes.append(a) alarmtimes.sort() while True: if (utime.time() - start) >= alarmtimes[current]: alarm(types[at[alarmtimes[current]]]) current += 1 utime.sleep(0.5) class MyMenu(simple_menu.Menu): color_1 = color.CAMPGREEN color_2 = color.CAMPGREEN_DARK def on_select(self, name, index): run(config['presets'][name]) types = config['alarmtypes'] menu = [] for m in config['presets'].keys(): menu.append(m) MyMenu(menu).run()