Toggle Navigation
Hatchery
Eggs
dragonled
__init__.py
Users
Badges
Login
Register
__init__.py
raw
Content
# Press the green Play button on the right to start the simulation. # # Your code will run, and then you'll get the MicroPython REPL. # # The REPL is an interactive prompt where you can type python commands and see the results immediately. # Type help() for MicroPython API cheat sheet. To paste code into the REPL press Ctrl+E. # # Press the blue pushbutton to interact with the example. import display import buttons import sys import machine APP_PATH = "/".join(__file__.split("/")[:-1]) sys.path.append(APP_PATH) import dragon import restart print("Hello, MCH2022 Badge!") display.drawFill(display.WHITE) display.drawText(10, 10, "Hello, MCH2022 badgePython!", display.MAGENTA, "roboto_regular18") display.flush() colors = [0xFFFFFF, 0x000000] text = ["PARTY", "HARD!"] # calculate the nicknames dimension so we can center it (and don't need any hardcoded sizes) text_x = int((display.width() - display.getTextWidth(text[0], "PermanentMarker36")) / 2) text_y = int((display.height() - display.getTextHeight(text[0], "PermanentMarker36")) / 2) def displayAnimated(): i = 0 j = 0 while True: displayNext(i) i = (i + 1) % 2 dragon.brightup() machine.lightsleep(100) def displayNext(i): display.drawFill(colors[(0+i)%2]) # display.drawPng(0, 0, nyan[i]) display.drawText(text_x, text_y, text[i], colors[(1+i)%2], "PermanentMarker36") display.flush() def on_action_btn(pressed): if pressed: display.drawText(10, 60, "Hello, button!", display.BLUE, "roboto_regular18") display.flush() print("Action button pressed!") buttons.attach(buttons.BTN_A, on_action_btn) buttons.attach(buttons.BTN_HOME, restart.button_exit_app) buttons.attach(buttons.BTN_B, dragon.lightup) buttons.attach(buttons.BTN_SELECT, dragon.brightdown_btn) buttons.attach(buttons.BTN_UP, dragon.brightup_btn) buttons.attach(buttons.BTN_DOWN, dragon.brightdown_btn) buttons.attach(buttons.BTN_RIGHT, dragon.brightanimation) displayAnimated()