6 posts • Page 1 of 1
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.
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
Hello. This is the code I am using. It does start the video as planned but I cannot stop the PIR detecting movement.
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")
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")
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.