I am trying to play a random video file upon an input from a PIR sensor.
Rasberry Pi 3, running Rasbian.
Problem is, I don't know what I'm doing and just trying to hack together different files.
So far, I have the PIR detection script (pirDetect) working, and the playback file also works, except instead of playing back a random file in the directory, it plays back the same one over and over on every detection.
Here is what I am using at the moment:
#!/usr/bin/python
import subprocess as sp
import time
from pirDetect import *
import random
import os
directory = "."
video = ["omxplayer", "filename", "-o", "local"]
scareFile = random.choice(os.listdir(directory))
def onMotion(currState):
if currState:
video[1] = scareFile
subVideo = sp.Popen(video)
while subVideo.poll() is None:
time.sleep(.1)
objDetect = detector(7)
objDetect.subscribe(onMotion)
objDetect.start()
Thanks in advance for any help you can provide.