Quirk with resetting the time variable

Haku

Senior Member
There's an odd quirk with the time variable I've noticed once before and now again when programming a countdown timer setup which uses a single button for control.

I coded it so pressing and holding the button down for one second turns off the countdown timer, but the time needed to hold the button down is never one second it's always less than one second. The specific piece of code works like this:

Code:
time=0
do while pushbutton=1
loop
if time>1 then:(turn off countdown code here):endif
It appears that setting the time variable to 0 doesn't reset whatever controls the incrementation of the time variable. Is there a way of resetting that thing?

I'm using a breadboarded 18m2 but will transfer code+circuit to a soldered 08m2.
 

Technical

Technical Support
Staff member
Time is designed to count the approximate number of whole seconds elapsed, not to be used for very small time delays. In this case you would be far better with a for next loop checking the switch 50 times with a 'pause 20' e.g. as a starting point

Code:
for b1 = 1 to 50
if pushbutton = 0 then escape
pause 20
next b1

escape:
if b1 < 50 then....
Technically time works by counting 50 lots of the servo tick (20ms ticks). However the current 'tick-count' is not changed by adjusting the time variable manually, so if tick-count equals 25 when the time variable is manually changed then the next time increment will occur after 0.5s, not after 1s.
 

Haku

Senior Member
Thanks for the information on how time increments, I thought there would be a simple command rather than a for..next loop solution. Oh well.
 
Top