This is my first RPi AND my first Python project! I've become stuck with a few problems that seem easy to do, but are difficult for me because I'm not sure what I should be looking up.
The project is this: I have a list of 10 functions that each play an mp4 file. A CO2 sensor will call each function when the sensor output value goes below a certain number (let's say 700). It needs to play the videos in order. Example: blow into the sensor, output value goes down, video 1 plays. Blow into the sensor again, video 2 plays, etc. Once video 10 plays, it resets so the next video played will be video 1.
So basically I need Python to always be reading the sensor output, and to play the video ONCE when the value goes below 700. For example, when you blow into the sensor, the value dips from around 800 to around 600. It seems that just saying "if value < 700, play video" it will play the video for every returned value that's less than 700. That means it'll attempt to play the video 100 times or more!
Note: I have not been able to successfully make something happen when the sensor value goes below 700, even print a string. Here's an example of something that didn't work. What am I doing wrong here?
Code: Select all
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
while True:
line = ser.readline()
if line < 700:
print "Readout is less than 600."
else:
pass
ser.close()
Thank you for reading this far, any guidance is appreciated!
Code: Select all
import os
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
while True:
line = ser.readline()
# -------------functions for black image to display when no one is blowing into the sensor-------------
def blank():
os.system("sudo fbi -a --noverbose -T 1 blk.jpg")
def endblank():
os.system("sudo killall fbi")
# -------------functions for videos-------------
def vid1():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/01.mp4")
def vid2():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/02.mp4")
def vid3():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/03.mp4")
def vid4():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/04.mp4")
def vid5():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/05.mp4")
def vid6():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/06.mp4")
def vid7():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/07.mp4")
def vid8():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/08.mp4")
def vid9():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/09.mp4")
def vid10():
os.system("xterm -fullscreen -fg black -bg black -e omxplayer -o hdmi -r /home/pi/Desktop/10.mp4")
# -------------list of videos-------------
video = [vid1, vid2, vid3, vid4, vid5, vid6, vid7, vid8, vid9, vid10]
# -----------------------------------------
if line < 600:
endblank()
# Here's where I need help!
else:
blank()