I believe you can. I was unable to (quickly) find an example to verify, but it should not take but a moment to try it.
I think that one of the reasons I was unable to find an example is that long pauses are often avoided because the processor does nothing during a pause but spin a tight, uninterruptable, loop. Most often pauses are kept short purposely, during longer waits other constructs or functions are used to fill the time - such as NAP or SLEEP - that put the processor into low power mode.
Consider: Pause 10000. For approximately 10 seconds nothing happens. Any display is not updated, any serial communications fail, no user input will be serviced, and no interrupts are processed. All that is going on is that the processor is burning thru (battery most significantly) power without any other purpose but to wait.
Now:
For LP0 = 0 to 9 'Loop 10 times (Loop 10 times (Loop 10 times))
For LP1 = 0 to 9 'Loop 10 times (Loop 10 times)
For LP2 = 0 to 9 'Loop 10 times
Pause 10 'Pause 10
Next LP2
Next LP1
Next LP0
In this example the processor pauses an equivalent time, but interrupts can be serviced (between the much shorter pauses) and, by inserting code inside the outer loops, buttons can be checked, displays updated...
Typically, when there is truly nothing for the processor to do, delays are managed with functions that put the processor "to sleep" so as to save power. In your case, this has the added benefit that these functions are not particularly accurate - thus adding a random element to their timing.
One last...
For no particular reason, you may consider a construct to make a loop of a known duration, then call the loop a random number of times, as:
Main:
Toggle LED
For RandomDuration = 0 to (RandomNumber between 1 and 10)
Gosub PauseTime
Next RandomDuration
Goto Main
PauseTime:
For LP1 = 0 to 9
For LP2 = 0 to 9
Pause 100
Next LP2
Next LP1
Return
The only advantage I see in this scheme is that the random waits will be (likely) clearly different in duration between one and the next, where straight random pauses may vary by hundreds or even thousands of cycles and not be noticeably different in duration to the user.
HTH,
Another Buzz Aldrin




Bookmarks