Go Down

Topic: Help with multiple PING code. (Read 756 times) previous topic - next topic


I'm trying to create code for a waterslide that checks when riders have passed check points in the slide, advises the slide operator if the rider has stopped, and that lights a "go" light when riders have cleared appropriate check points within a certain amount of time. Pretty simple so far, but I also need the programming be "smart" so that it knows when to expect riders to pass. The program needs to throw alarms when riders are supposed to pass a checkpoint but don't (based off the program sensors expecting an rider-ie section 2 isn't expecting a rider unless the rider has entered the slide and has cleared section 1, and vice-versa: if the rider has passed section 2 but no one is expected in section 1 the "go" light will still turn on).

I'm using parallax PING sensors so that I can adjust for distance and rushing water, and an Arduino Mega 2560, LED's, on/off toggle, and external reset switch

An example situation would be:
The 1st rider enters the slide and a beginning PING sensor (ping1) tells the program that it should expect an input from ping2 within Xseconds and if not, turns the stop1LED on (//meaning the rider has stopped). If the rider passes ping2 within the allotted Xseconds it triggers a goLED (Green LED) light. ping2 needs to function simultaneously as a sensor/trigger that tells the program that it should be expecting an input soon from the 1st rider at ping3, and expecting the 2nd rider to pass ping2, and will only digitalWrite (goLED, HIGH) if ping2 and ping 3 are cleared (via an appropriate distance reading) . Further if the 1st rider doesn't pass ping3 within Yseconds, then it will turn on a different red LED (stop2LED), or if the 2nd rider doesn't pass ping2 within the same Xseconds, it triggers a digitalWrite (stop1LED). If both sensors make a reading in time it says to digitialWrite (goLED, HIGH) turning on the Green LED, telling the slide operator it is safe for another rider to enter. And this continues on.

I've attatched the code file for what I have so far:

Within this I need the goLED light to stay lit for a few seconds so the operator can see it. I could use the delay (5000) but that seems to stop everything else until the delay completes. How can I light the goLED for 5 seconds and still run the reading of sensors in the background?

Again, sorry for the mixing of syntax and explanation...


The example BlinkWithoutDelay program will show you how to do timing without blocking code execution caused by using delay()
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Also, you may want to look into the NewPing library http://playground.arduino.cc/Code/NewPing and the examples there for handling multiple sensors, while avoiding the delay() function.
Arduino experiments, resources and hacks http://42bots.com

Go Up