Skip to content

Instantly share code, notes, and snippets.

@Pindar
Last active July 7, 2018 07:11
Show Gist options
  • Save Pindar/79a914e67214668266501d63ad4e2e7f to your computer and use it in GitHub Desktop.
Save Pindar/79a914e67214668266501d63ad4e2e7f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
from subprocess import check_output
from gpiozero import Button
from signal import pause
import time
def playPause():
os.system("mpc toggle")
def volumeUp():
print("volumeUp")
os.system("mpc -q volume +1")
def volumeDown():
print("volumeDown")
os.system("mpc -q volume -1")
def next():
print("next")
os.system("mpc next")
time.sleep(5)
speakCurrent()
def prev():
print("prev")
os.system("mpc prev")
time.sleep(5)
speakCurrent()
def speakCurrent():
os.system("mpc toggle")
os.system("echo $(mpc current) | /usr/bin/flite -voice slt")
os.system("mpc toggle")
mainBtn = Button(17, pull_up=True)
mainBtn.when_pressed = playPause
#
nextBtn = Button(23, pull_up=True)
nextBtn.when_pressed = next
#
prevBtn = Button(22, pull_up=True)
prevBtn.when_pressed = prev
#
volumeUpBtn = Button(24, pull_up=True)
volumeUpBtn.when_pressed = volumeUp
#
volumeDownBtn = Button(25, pull_up=True)
volumeDownBtn.when_pressed = volumeDown
os.system("/usr/bin/mpc load antenne \
egoFM \
lina \
ludwig \
oldies-but-goldies \
radio-charivari-2-rosenheim \
radio-charivari-rosenheim \
rockantenne")
os.system("mpc play")
time.sleep(5)
speakCurrent()
pause()
[Unit]
Description=Play Radio on Startup
After=mpd.socket
Requires=mpd.socket
[Service]
TimeoutSec=0
ExecStart=/home/pi/79a914e67214668266501d63ad4e2e7f/radio-gpio.py
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment