From 02954cd87c1689f0789e03d25c91d112d9d5e670 Mon Sep 17 00:00:00 2001 From: Matthias Blankertz Date: Tue, 23 Dec 2025 11:49:28 +0100 Subject: [PATCH] feat: Visual feedback on LEDs during startup Set the LEDs to a fixed color during bootup to show the different modes: - Orange when the device is booting - Red when button 0 is held and the device goes to a shell - Blue when button 1 is held and the device goes to AP mode instead of joining the configured WiFi network - Red blinking when the run() method throws an exception for any reason Signed-off-by: Matthias Blankertz --- software/src/main.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/software/src/main.py b/software/src/main.py index d3a0ca3..cf1deea 100644 --- a/software/src/main.py +++ b/software/src/main.py @@ -10,6 +10,7 @@ import network import os import time import ubinascii +import sys # Own modules import app @@ -73,13 +74,18 @@ DB_PATH = '/sd/tonberry.db' config = Configuration() +# Setup LEDs +np = NeoPixel(hwconfig.LED_DIN, config.get_led_count(), sm=1) +np.fill((32, 32, 0)) +np.write() + def run(): asyncio.new_event_loop() - # Setup LEDs - np = NeoPixel(hwconfig.LED_DIN, config.get_led_count(), sm=1) if machine.Pin(hwconfig.BUTTONS[1], machine.Pin.IN, machine.Pin.PULL_UP).value() == 0: + np.fill((0, 0, 32)) + np.write() # Force default access point setup_wifi('', '') else: @@ -141,7 +147,24 @@ def builddb(): os.sync() +def error_blink(): + while True: + np.fill((32, 0, 0)) + np.write() + time.sleep_ms(500) + np.fill((0, 0, 0)) + np.write() + time.sleep_ms(500) + + if __name__ == '__main__': time.sleep(1) if machine.Pin(hwconfig.BUTTONS[0], machine.Pin.IN, machine.Pin.PULL_UP).value() != 0: - run() + try: + run() + except Exception as ex: + sys.print_exception(ex) + error_blink() + else: + np.fill((32, 0, 0)) + np.write()