diff --git a/preload/main.py b/preload/main.py index 53051b6a22b6b81b71729e69a0b387ca79ac1ee2..0f5a0fd8a1e413c399b0c8f4eae8c9431c57a094 100644 --- a/preload/main.py +++ b/preload/main.py @@ -180,31 +180,43 @@ class Clock: def loop(self): colored = False button_pressed = False + update_counter = 0 + new_theme = self.theme while True: try: - with display.open() as disp: + if update_counter == 0: + update_counter = 10 - self.updateClock(disp) - if self.run_once: - break + with display.open() as disp: + # update the display + self.updateClock(disp) - # check for button presses - v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) - if v == 0: - button_pressed = False + # check theme + if new_theme != self.theme: + self.setTheme(new_theme) + self.writeConfig() - if not button_pressed and v & buttons.BOTTOM_LEFT != 0: - button_pressed = True - self.setTheme(self.theme - 1) - self.writeConfig() - elif not button_pressed and v & buttons.BOTTOM_RIGHT != 0: - button_pressed = True - self.setTheme(self.theme + 1) - self.writeConfig() + update_counter = update_counter - 1 - utime.sleep_ms(250) + if self.run_once: + break + + # check for button presses + v = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) + if v == 0: + button_pressed = False + + if not button_pressed and v & buttons.BOTTOM_LEFT != 0: + button_pressed = True + new_theme = self.theme - 1 + elif not button_pressed and v & buttons.BOTTOM_RIGHT != 0: + button_pressed = True + new_theme = self.theme + 1 + + utime.sleep_ms(25) except OSError: + # leds.set(1, (255, 0, 0)) pass except KeyboardInterrupt: