I have a problem with a program we are working on.
The code below is something we want to use in a small game we are creating at work.
Now the idea is that an image is projected onto the floor, and this image is divided into 3 lanes (it has something to do with an interactive traffic circuit for children) and each lane has his own IR sensor to see over what lane the child is driving and depending on what lane it must play either one sound or another.
This is the code i am using for the moment, and it kinda works. When i start the program, the first image is displayed, when i trip the sensor, the sound starts playing, but then it stops. It does not go to the second step in the program.
I'm guessing the problem should be with the IF and ELSE statement. the thing is, it only needs to do something when drive past 1 of the 3 sensors.
So it needs to project the image.
Then check the 3 sensors at the same time for movement while still displaying the image.
If movement is detected, play the mp3 file
And this together should be 15 seconds before going to the next step. in the final code there are going to be a lot more steps but i just included the first 2 as an example.
Hope it is only a small thing and that somebody can help me out with this.
With kind regards,
Jimmy
Code: Select all
import RPi.GPIO as IO
from time import sleep
import os
import subprocess
while True:
#=========================================================================================
#stap1 - Image : pok01 - totale sequentie tussenstap duurt 15 seconden - Hindernis Midden
#=========================================================================================
image = subprocess.Popen(["feh", "--hide-pointer", "-x", "-q", "-F", "-B", "black", "-g", "1280x800", "/home/pi/ameco/images/pok01.jpg"])
IO.setwarnings(False)
IO.setmode (IO.BCM)
#----------Linkersensor - Baan 1 - IO 14----------
IO.setup(14, IO.IN, pull_up_down=IO.PUD_DOWN)
IO.wait_for_edge(14, IO.RISING)
if(IO.input(14)==True):
os.system('mpg123 "/home/pi/ameco/sound/fail01.mp3" &') #afspelen geluid applaus
else:
#----------Middensensor - Baan 2 - IO 18----------
IO.setup(18, IO.IN, pull_up_down=IO.PUD_DOWN)
IO.wait_for_edge(18, IO.RISING)
if(IO.input(18)==True):
os.system('mpg123 "/home/pi/ameco/sound/applause1.mp3" &') #afspelen geluid applaus
else:
#----------rechtersensor - Baan 3 - IO 24----------
IO.setup(24, IO.IN, pull_up_down=IO.PUD_DOWN)
IO.wait_for_edge(24, IO.RISING)
if(IO.input(24)==True):
os.system('mpg123 "/home/pi/ameco/sound/fail02.mp3" &') #afspelen geluid applaus
else:
tijdb = 15
sleep(tijdb) #wachttijd 15 seconden
IO.cleanup()
image.kill()
os.system('clear') #scherm wissen na tijd pauze
#=========================================================================================
#stap2 - Image : pok02 - totale sequentie tussenstap duurt 15 seconden - Hindernis Links
#=========================================================================================
image = subprocess.Popen(["feh", "--hide-pointer", "-x", "-q", "-F", "-B", "black", "-g", "1280x800", "/home/pi/ameco/images/pok02.jpg"]) #display foto
IO.setwarnings(False)
IO.setmode (IO.BCM)
#----------Linkersensor - Baan 1 - IO 14----------
IO.setup(14, IO.IN, pull_up_down=IO.PUD_DOWN)
IO.wait_for_edge(14, IO.RISING)
if(IO.input(14)==True):
os.system('mpg123 "/home/pi/ameco/sound/applause2.mp3" &') #afspelen geluid applaus
else:
#----------Middensensor - Baan 2 - IO 18----------
IO.setup(18, IO.IN, pull_up_down=IO.PUD_DOWN)
IO.wait_for_edge(18, IO.RISING)
if(IO.input(18)==True):
os.system('mpg123 "/home/pi/ameco/sound/fail03.mp3" &') #afspelen geluid applaus
else:
#----------rechtersensor - Baan 3 - IO 24----------
IO.setup(24, IO.IN, pull_up_down=IO.PUD_DOWN)
IO.wait_for_edge(24, IO.RISING)
if(IO.input(24)==True):
os.system('mpg123 "/home/pi/ameco/sound/fail01.mp3" &') #afspelen geluid applaus
else:
tijdb = 15
sleep(tijdb) #wachttijd 15 seconden
IO.cleanup()
image.kill()
os.system('clear') #scherm wissen na tijd pauze