PDA

View Full Version : Delay Function


JohnBode
06-24-2010, 08:58 PM
Timers don't work very well as delay functions in SNAPpy because they are not pre-emptive. A simple delay function that delays x milliseconds would be helpful.

Ozzie
07-28-2010, 08:34 AM
I second this request.

Unless someone has a better idea?

Oz

kbanks
07-28-2010, 09:15 PM
If there were a delay function in SNAPpy, then while it was running the unit would be unable to interact with the radio and the serial ports (etc.). It wouldn't be able to route or forward multicasts for other nodes (etc.)

Ideally, write your SNAPpy scripts so that they are state machine based (event driven). This way the node can be accomplishing other things while the "delay interval" elapses.

Worst case, if you have a spare GPIO pin (for example, unconnected), then you can use the pulsePin() built-in with a negative duration to generate a "blocking" delay. Refer to the SNAP Reference Manual.

Ozzie
07-28-2010, 09:26 PM
OK..that's a better idea.

Thanks
Oz

gre7g
07-29-2010, 09:44 AM
Here's another trick you can use from Kevin's advice:

Use the pulsePin function on an input pin instead of an output pin. You still get the blocking delay, but there is no external effect. That way you don't have to waste a pin, just to get the delay.