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")