#!/usr/bin/env python import RPi.GPIO as GPIO import time import subprocess GPIO.setwarnings(False) LedPin1 = 17 #0 # pin17 --- Pi indicator led 1 LedPin2 = 27 #1 LedPin3 = 22 #2 LedPin4 = 10 #3 LedPin5 = 9 #4 LedPin6 = 11 #5 Int_Input = 14 # toggle signal from Arduino to use in this program as an interrupt, program will then check which button was pushed on the remote BtnPin1 = 15 #0 # these are the decoded values of the IR remote from Arduino that will be checked when interrupt occurs BtnPin2 = 18 #1 BtnPin3 = 23 #2 BtnPin4 = 24 #3 BtnPin5 = 25 #4 BtnPin6 = 8 #5 def setup(): GPIO.setmode(GPIO.BCM) # Numbers GPIOs by chip number GPIO.setup(LedPin1, GPIO.OUT) # Set LedPin mode to output for visual indication GPIO.setup(LedPin2, GPIO.OUT) GPIO.setup(LedPin3, GPIO.OUT) GPIO.setup(LedPin4, GPIO.OUT) GPIO.setup(LedPin5, GPIO.OUT) GPIO.setup(LedPin6, GPIO.OUT) GPIO.setup(Int_Input, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BtnPin1, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) GPIO.setup(BtnPin2, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BtnPin3, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BtnPin4, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BtnPin5, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BtnPin6, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.output(LedPin1, GPIO.LOW) # start with Leds off GPIO.output(LedPin2, GPIO.LOW) GPIO.output(LedPin3, GPIO.LOW) GPIO.output(LedPin4, GPIO.LOW) GPIO.output(LedPin5, GPIO.LOW) GPIO.output(LedPin6, GPIO.LOW) print ("btn.py is running ...") def swLed(ev=None): if GPIO.input(BtnPin1): # remote button (0) GPIO.output(LedPin1, GPIO.HIGH) #subprocess.call(["sudo","./test.sh","stop"]) subprocess.call(["sudo","killall","omxplayer.bin"]) else: GPIO.output(LedPin1, GPIO.LOW) if GPIO.input(BtnPin2): # remote button (1) GPIO.output(LedPin2, GPIO.HIGH) subprocess.call(["sudo","./test.sh","start"]) else: GPIO.output(LedPin2, GPIO.LOW) if GPIO.input(BtnPin3): # remote button (2) GPIO.output(LedPin3, GPIO.HIGH) subprocess.call(["sudo","./test1.sh","start"]) else: GPIO.output(LedPin3, GPIO.LOW) if GPIO.input(BtnPin4): # remote button (3) GPIO.output(LedPin4, GPIO.HIGH) subprocess.call(["sudo","./test2.sh","start"]) else: GPIO.output(LedPin4, GPIO.LOW) if GPIO.input(BtnPin5): # remote button (4) GPIO.output(LedPin5, GPIO.HIGH) subprocess.call(["sudo","./test3.sh","start"]) else: GPIO.output(LedPin5, GPIO.LOW) if GPIO.input(BtnPin6): # remote button (5) GPIO.output(LedPin6, GPIO.HIGH) subprocess.call(["sudo","./test4.sh","start"]) else: GPIO.output(LedPin6, GPIO.LOW) def loop(): GPIO.add_event_detect(Int_Input, GPIO.FALLING, callback=swLed, bouncetime=300) # wait for falling and set bouncetime to prevent the callback function from being called multiple tim$ while True: time.sleep(1) # Don't do anything def destroy(): GPIO.cleanup() # Release resource if __name__ == '__main__': # Program start from here setup() try: loop() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. destroy()