Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import sleep
- import subprocess
- import os
- import RPi.GPIO as GPIO
- GPIO.cleanup()
- GPIO.setmode(GPIO.BOARD)
- # Buttons
- button1 = 21 # GPIO 10 PIN 19
- button2 = 19 # GPIO 09 PIN 21
- button3 = 15 # GPIO 22 PIN 15
- button4 = 11 # GPIO 17 PIN 11
- button5 = 7 # GPIO 04 PIN 7
- # Control LED
- ledout = 8 # GPIO 14 PIN 8
- ledout2 = 16 # GPIO 23 PIN 16
- LEDON = GPIO.LOW
- LEDOFF = GPIO.HIGH
- # DEBUG
- debug = 0
- # different modes
- next_prev_mode = 0
- volume_mode = 1
- # current mode
- state = next_prev_mode
- # Set Input Buttons
- GPIO.setup(button1, GPIO.IN)
- GPIO.setup(button3, GPIO.IN)
- GPIO.setup(button2, GPIO.IN)
- GPIO.setup(button4, GPIO.IN)
- GPIO.setup(button5, GPIO.IN)
- # Set Output LED
- GPIO.setup(ledout, GPIO.OUT)
- GPIO.setup(ledout2, GPIO.OUT)
- # and Turn it Off
- GPIO.output(ledout, LEDOFF)
- GPIO.output(ledout2, LEDOFF)
- # Function Blink LED
- def blink():
- GPIO.output(ledout, LEDON)
- sleep(0.1)
- GPIO.output(ledout, LEDOFF)
- # Function Call MPC
- def mpc(doit,doit2):
- blink()
- if (doit2 ==""):
- p = subprocess.Popen(["mpc", doit], stdout=subprocess.PIPE)
- else:
- p = subprocess.Popen(["mpc", doit,doit2], stdout=subprocess.PIPE)
- output, err = p.communicate()
- print "*** Running mpc \"",doit," ",doit2,"\" command ***\n", output, " err:",err
- print output
- def cmdit(doit):
- blink()
- p = os.system(doit)
- print "*** Running cmdit \"",doit,"\" command ***\n"
- #
- while True:
- # X - - - - button 5 button is pressed
- if ( GPIO.input(button5) == True ):
- if (debug == 1) : print("pressed button5", state)
- GPIO.output(ledout, LEDON)
- mpc("volume","100")
- sleep(1.1)
- GPIO.output(ledout, LEDOFF)
- # - X - - - button 4 button is pressed
- if ( GPIO.input(button4) == True ):
- if (debug == 1) : print("pressed button4 ", state)
- if (state == 0 ):
- state = volume_mode
- blink()
- print ("Volume Mode")
- GPIO.output(ledout2, LEDON)
- else:
- state = next_prev_mode
- blink()
- print ("Next Prev Mode")
- GPIO.output(ledout2, LEDOFF)
- # - - N - - state next button is pressed
- if ( GPIO.input(button3) == True ):
- if (debug == 1) : print("pressed button3", state)
- if (state == next_prev_mode):
- mpc("prev","")
- mpc("current","")
- else:
- mpc("volume","-10")
- mpc("status","")
- # - - - - P state prev button is pressed
- if ( GPIO.input(button1) == True ):
- if (debug == 1) : print("pressed button1", state)
- if (state == next_prev_mode):
- mpc("next","")
- mpc("current","")
- else:
- mpc("volume","+10")
- mpc("status","")
- # - - - X - pause button is pressed
- if ( GPIO.input(button2) == True ):
- if (debug == 1) : print("pressed button2 ", state)
- mpc("toggle","")
- sleep(0.2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement