I have a PiFace on a RaspberryPi, and it works great, but there is a several second delay between when the input switches to when the script responds. Can someone tell me where to find/change this delay time? Thanks, Jim
I have a PiFace on a RaspberryPi, and it works great, but there is a several second delay between when the input switches to when the script responds. Can someone tell me where to find/change this delay time? Thanks, Jim
I'm not blaming anything, I just wanted help in removing the delay which caused it to not work consistently. People don't stand at a mirror for very long in a haunted house, so many miss the scare. I think the pygame.time.delay(5750) was intended to be a delay between the scare and the system being ready for the next event trigger, (at least that's what I want it to do), so it won't keep running if the eye is triggered again right away.
The mp3 is around 10 seconds long, but I will try what you have suggested and see how it works. Thanks!
After reading your last comment (https://www.element14.com/community/message/247865/l/re-piface-input-delays#247865 ) I'm not sure if I understand well what your code wants to do.
Can you draw the scenario of what you try to achieve when no one presses a button (application in rest) , and when someone presses a button?
The idea is the display has a black screen (blackscreen.jpg) so the mirror has the person's reflection on it.
This is what it does until the eye is triggered by somebody, so a small delay is ok, just not how long it is currently.
When the input goes high(the eye is triggered), I want the display to switch to the creepyclown.jpg image and the mp3 file plays until it is done.
I am also turning off a light with the relay output at the same time.
Once the audio file is done, I want it to reset back to the black screen and wait for the next person to trigger the eye.
Everything actually works, surprisingly, except the delay that I inadvertently used improperly, causes it to wait for several seconds once the eye is triggered, to display the image and play the audio file.
And because of this mistake, the eye only does the True routine when it is held high for those several seconds, which is not how I want it. I will try to just change the delay time and see what that does.
Well, I found out that whatever value I put in the else: pygame.time.delay(####) is how long the eye must be triggered before the True event starts. Does that make sense? I guess it will work now that I lowered the value, but I don't see why that effects the script when the input is true, and not just when it is not true.
The structure of such a program would be something like:
while true
if eye signal active then
do whatever needs to be done.
while eye signal active
do nothing / wait.
end while
end if
// other stuff that may need checking/doing. But don't take too long!
sleep a short time.
end while
For debugging you can add "print something" to the "other stuff" That way you can see how fast it runs through the loop. Sleep a short time, 10ms is reasonable, but will have your terminal window scrolling like mad. For debugging I prefer having it run a bit (10 to 50 times) slower. Currently working on a project with exaclty the same. In production the reporting will be done every 10ms, 100x per second. Now for debugging I prefer having it a bit slower.
Python is a space based language so it's best to ensure the spacing is correct between blocks and that either spaces or tabs are used consistently; do not mix them however I prefer spaces since different editor set tabs to different space length. Since you pasted your code as without Syntax Highlighting its not possible to see if this is an issue.
Also, you might want to try to initialize the PiFace either before reading the device or at the end of your while loop to ensure the PiFace is at a known state before reading it. Just add what you had at the top of the code:
pifacedigitalio.init()
For the Remote Horse Feeder project I worked on sometime back, I had this note in one of the blog posts regarding the Digital 2:
[Pi IoT] - Remote Horse Feeder System #6 : OpenHAB, Pi Face and MQTT
The sensor I used for the Motion Sensing is the Parallax PI Sensor rev B. This is connected to the Pi Face Digital 2 Input 3, 5V and Ground. (NOTE: Since the Digital 2 Inputs are by default pulled up to 5V, I ended up having to put a 10K resistor between GND and Pin 3 to pull the pin low when the PIR sensor was on.)
Perhaps when your sensor is on, it is pulling the pin low on the Digital 2 thus going to the else statement. Try changing the check for if input_state0 to:
if input_state0==0:
I have noticed a small delay when using Python, particularly when performing serial communications. I presumed it was primarily due to running an interpreter instead of actual machine instructions, but I never did that investigation. I use Python for determining if an procedure or algorithm will provide me with what I want, because it is well structured enough and the write-run-test loop is very quick. Almost always, after I get things the way I want, I switch over to C to get performance levels up. What's fun is in many cases it only requires putting semi colons on the end of the lines.
Jack