This works great.
What I also would like is to use a relay to turn on a lightbulb when the button is pressed.
So when the button is pressed, the video will start to play and a light switches on.
The light has to turn on for 1 minute.
When I press a second button, another video has to start playing (the first video is stopped) and another light must switch on AND all other lights must turn off.
The part of playing the video is working. Press button 1 and video 1 is playing. By pressing button 2, video 2 starts playing.
Now I need to use a relay to switch on a light when a video starts to play.
I don't know how to start here and to incorporate this into my exisiting code.
Can anybody help me with this?
Below the code thats works for starting the video's.
Code: Select all
import RPi.GPIO as GPIO
import os
import sys
from subprocess import Popen
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Pushbutton
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Pushbutton
movie1 = ("/var/www/html/dieselloc.mp4")
movie2 = ("/var/www/html/snhv2019.mp4")
last_state1 = True
last_state2 = True
input_state1 = True
input_state2 = True
player = False
while True:
#Read states of inputs
input_state1 = GPIO.input(7)
input_state2 = GPIO.input(11)
#If GPIO(7) is shorted to Ground
if input_state1 != last_state1:
if (player and not input_state1):
os.system('killall omxplayer.bin')
omxc = Popen(['omxplayer', '-b', movie1])
player = True
elif not input_state1:
omxc = Popen(['omxplayer', '-b', movie1])
player = True
#If GPIO(11) is shorted to Ground
elif input_state2 != last_state2:
if (player and not input_state2):
os.system('killall omxplayer.bin')
omxc = Popen(['omxplayer', '-b', movie2])
player = True
elif not input_state2:
omxc = Popen(['omxplayer', '-b', movie2])
player = True
#Set last_input states
last_state1 = input_state1
last_state2 = input_state2