-
- Posts: 33
- Joined: Sat Dec 26, 2015 2:36 pm
Use a PIR to start a video then disable it.
Hello. I am doing a project with my grand children where a PIR is used to start a video. When that has stopped they push a button to start another video. The problem I'm having is that all the programs I've found to use the PIR have a while loop so the video keeps playing. Is there a command to stop it or is there another program that will just detect it once? Thanks.
-
- Posts: 916
- Joined: Tue Dec 15, 2015 4:55 pm
- Location: Detroit, MI USA
- Contact: Website
Re: Use a PIR to start a video then disable it.
What is the code for the while loop? I'd think you could A. Put a command in your while lop to stop recording when pir goes inactive and B. Nest that start stop stuff within a for loop that numerically increments to change the name of the file every iteration(so you don't overwrite the last file).
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics
-
- Posts: 33
- Joined: Sat Dec 26, 2015 2:36 pm
Re: Use a PIR to start a video then disable it.
Thanks. When I get home I'll copy the code here for you to see.
-
- Posts: 33
- Joined: Sat Dec 26, 2015 2:36 pm
Re: Use a PIR to start a video then disable it.
Hello. This is the code I am using. It does start the video as planned but I cannot stop the PIR detecting movement.
Thanks.
Code: Select all
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)
while True:
if GPIO.input(4):
os.system("omxplayer -o hdmi /home/pi/output.mp4")
Re: Use a PIR to start a video then disable it.
Code: Select all
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)
GPIO.setup(7, GPIO.IN)
runvideo = 0
while runvideo ==0:
if GPIO.input(4):
os.system("omxplayer -o hdmi /home/pi/output.mp4")
runvideo = 1
while True:
if GPIO.input(7):
os.system("omxplayer -o hdmi /home/pi/another.mp4")
-
- Posts: 33
- Joined: Sat Dec 26, 2015 2:36 pm
Re: Use a PIR to start a video then disable it.
Thank you very much for your help. I would never of got the PIR sorted without your help. I played around with the second bit of the code so that a button push starts a second video. It was a code from CamJam EduKit that I'd modified. This is a great way to learn even though it can be a bit frustrating sometimes. It's good to know that there are so many people out there to help when it does get frustrating.