From 8466e77a618972b065df30aa5d316337882c2873 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 30 Dec 2025 23:54:17 +0100 Subject: [PATCH] Fix button handler --- esp32-wifi/button_handler.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/esp32-wifi/button_handler.py b/esp32-wifi/button_handler.py index 7ec31d9f..63401dd7 100644 --- a/esp32-wifi/button_handler.py +++ b/esp32-wifi/button_handler.py @@ -1,10 +1,9 @@ import _thread -from typing import Callable from machine import Pin import time class ButtonHandler: - def __init__(self, pin : int, action : Callable[[], None]): + def __init__(self, pin , action): self.button = Pin(pin, Pin.IN, Pin.PULL_UP) self.action = action self._pressed = False @@ -20,7 +19,6 @@ class ButtonHandler: self._pressed = False time.sleep(0.1) - if __name__ == "__main__": def on_press(): print("Button action triggered") @@ -28,18 +26,4 @@ if __name__ == "__main__": btn = ButtonHandler(14, on_press) while True: - time.sleep(1) - - -"""# Track button state -button_pressed = False - -while True: - if not button.value(): # Button pressed (active low) - if not button_pressed: - button_pressed = True - print("Button pressed! Action triggered.") # Replace with your action - else: - button_pressed = False # Reset when button released - - time.sleep(0.01) # Small debounce delay""" \ No newline at end of file + time.sleep(1) \ No newline at end of file