From 9379df14f37c90dcc4eb9f3b95e66ce909d7b408 Mon Sep 17 00:00:00 2001 From: Karl Hudgell Date: Mon, 23 Sep 2024 11:03:42 +0100 Subject: [PATCH] add shuffle to button 4 --- buttons.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/buttons.py b/buttons.py index d20c7ef..71c7aef 100644 --- a/buttons.py +++ b/buttons.py @@ -7,7 +7,7 @@ client = create_client() create_config(client) # Set up GPIO pins for each button -BUTTON_PINS = [17, 18, 27] # Replace with your GPIO pin numbers +BUTTON_PINS = [17, 18, 27, 22] GPIO.setmode(GPIO.BCM) # Use BCM numbering @@ -31,7 +31,6 @@ 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): start_time = time.time() client = create_client() @@ -49,10 +48,18 @@ def button_callback_3(channel): print("Button 3 pressed briefly! Sending RADIO.") control_player(client, "RADIO") +def button_callback_4(channel): + print("Button 4 pressed!") + client = create_client() + control_player(client, "SHUFFLE") + control_player(client, "PLAY") + + # Add event detection for each button press GPIO.add_event_detect(BUTTON_PINS[0], GPIO.FALLING, callback=button_callback_1, bouncetime=200) GPIO.add_event_detect(BUTTON_PINS[1], GPIO.FALLING, callback=button_callback_2, bouncetime=200) GPIO.add_event_detect(BUTTON_PINS[2], GPIO.FALLING, callback=button_callback_3, bouncetime=200) +GPIO.add_event_detect(BUTTON_PINS[3], GPIO.FALLING, callback=button_callback_3, bouncetime=200) try: # Keep the script running to detect button presses