Преглед на файлове

add shuffle to button 4

Karl Hudgell преди 6 месеца
родител
ревизия
9379df14f3
променени са 1 файла, в които са добавени 9 реда и са изтрити 2 реда
  1. 9 2
      buttons.py

+ 9 - 2
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