From a7a38c6633b324bfa223708c549f6acee909e52d Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Fri, 20 Sep 2024 21:02:54 +0100 Subject: [PATCH] support held button --- buttons.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/buttons.py b/buttons.py index 45bb670..5ef3612 100644 --- a/buttons.py +++ b/buttons.py @@ -31,8 +31,20 @@ def button_callback_2(channel): control_player(client, "SKIP") control_player(client, "PLAY") +# Handling button 3 with a hold check def button_callback_3(channel): - print("Button 3 pressed!") + start_time = time.time() + + # Wait until the button is released or held for more than 3 seconds + while GPIO.input(BUTTON_PINS[2]) == GPIO.LOW: # Button is pressed (active low) + if time.time() - start_time >= 3: # Check if 3 seconds have passed + print("Button 3 held for 3 seconds! Sending RADIO2.") + client = create_client() + control_player(client, "RADIO2") + return # Exit after sending RADIO2 + + # If button was not held for 3 seconds, send RADIO + print("Button 3 pressed briefly! Sending RADIO.") client = create_client() control_player(client, "RADIO")