switches for mpc_play and mpc_stop [raspberrypi]

Screenshot_2

install software:
sudo apt-get install python-dev -y && sudo apt-get install python-rpi.gpio -y

create a python script:
nano /home/pi/play_stop.py

#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)

while True:
    if ( GPIO.input(24) == False ):
            os.system('mpc play &')
    if ( GPIO.input(25) == False ):
            os.system('mpc stop &')
    sleep(0.5);

make it executeable:
sudo chmod +x /home/pi/play_stop.py

add the script to startup:
sudo nano /etc/rc.local

and insert the following line before exit0:
sudo python /home/pi/play_stop.py &

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s