support held button
This commit is contained in:
parent
78f46cfce1
commit
a7a38c6633
14
buttons.py
14
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")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user