Last active
June 7, 2026 19:53
-
-
Save davedarko/316fd1e6ffdfcac0a957233bb2a77f16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| import app | |
| from events.input import Buttons, BUTTON_TYPES | |
| from system.hexpansion.config import * | |
| class ServoApp(app.App): | |
| def __init__(self): | |
| self.button_states = Buttons(self) | |
| self.text = "Press Confirm" | |
| def update(self, delta): | |
| if self.button_states.get(BUTTON_TYPES["CONFIRM"]): | |
| self.hexpansion_config = HexpansionConfig(1) | |
| self.init_servos() | |
| if self.button_states.get(BUTTON_TYPES["CANCEL"]): | |
| self.button_states.clear() | |
| self.minimise() | |
| def init_servos(self): | |
| self.ADDR = 0x09 | |
| self.i2c = self.hexpansion_config.i2c | |
| print("connecting to i2c") | |
| # Based on https://github.com/Hack-a-Day/2025-Communicator_Badge/blob/main/firmware/badge/hardware/keyboard.py | |
| pos = 36352 | |
| self.i2c.writeto_mem( | |
| self.ADDR, 0x00, pos.to_bytes(2, 'little') | |
| ) # KP_GPIO1 all ROW7:0 to KP matrix | |
| self.i2c.writeto_mem( | |
| self.ADDR, 0x02, pos.to_bytes(2, 'little') | |
| ) # KP_GPIO2 all COL7:0 to KP matrix | |
| self.i2c.writeto_mem( | |
| self.ADDR, 0x04, pos.to_bytes(2, 'little') | |
| ) # KP_GPIO3 all COL9:8 to KP matrix | |
| def draw(self, ctx): | |
| ctx.save() | |
| ctx.rgb(0.2,0,0).rectangle(-120,-120,240,240).fill() | |
| ctx.rgb(1,0,0).move_to(-80,0).text("Hello world") | |
| ctx.restore() | |
| __app_export__ = ServoApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment