Skip to content

Instantly share code, notes, and snippets.

@dtseiler
Last active March 31, 2025 19:12
Show Gist options
  • Select an option

  • Save dtseiler/0df74b30b37808ef7e287221631eccc0 to your computer and use it in GitHub Desktop.

Select an option

Save dtseiler/0df74b30b37808ef7e287221631eccc0 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#from gpiozero import Button, LED
from gpiozero import Button, LEDBoard
import time
import vlc
BTW_BUTTON_PIN=2
BTW_LED_PIN=17
GOAL_LED_PIN=21
btw_button = Button(BTW_BUTTON_PIN)
#btw_led = LED(BTW_LED_PIN)
#goal_led = LED(GOAL_LED_PIN)
leds = LEDBoard(
btw=BTW_LED_PIN,
goal=GOAL_LED_PIN
)
# Lights on to start
leds.on()
#btw_led.on()
#goal_led.on()
#
# VLC Player Setup
#
instance = vlc.Instance()
player = instance.media_player_new()
#player_events = player.event_manager()
#list_player = instance.media_list_player_new()
#list_events = list_player.event_manager()
#
# Button Press Callback
#
def button_pressed(pin):
print ("Button " + pin + " was pressed")
def play_music():
print("Playing music")
player.set_media(instance.media_new("/home/dts/19 Waterloo.mp3"))
player.play()
time.sleep(0.5)
duration = player.get_length()
print("Duration: " + str(duration))
while True:
btw_button.wait_for_press()
print("THE BUTTON WAS PRESSED!")
leds.off()
leds.btw.on()
play_music()
time.sleep(1)
leds.on()
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment