Timers - ozarchie/BlueBasic GitHub Wiki
TIMER <0-3>, <timeout in milliseconds> [REPEAT] GOSUB <line number>
TIMER <0-3> STOP
It's often useful to run bit of your program either at a particular time in the future, or repeatedly every so many seconds. To do this we use TIMERS.
Currently, four timers are supported.
Each timer can be created to run a specific section of the Basic program after a given number of milliseconds has elapsed.
A timer may choose to keep repeating ("REPEAT" text present) (e.g. execute every 5 seconds) or just run once ("REPEAT" text not present) (e.g. execute after 5 seconds and then stop).
For example:
10 TIMER 1, 2000 REPEAT GOSUB 1000
20 TIMER 2, 2000 GOSUB 2000
...
1000 PRINT "Hello again"
1030 RETURN
...
2000 PRINT "Hello and Goodbye"
2030 RETURN
The above example sets up timer 1. Every 2000 milliseconds, repeatedly, it will run the subroutine at line 1000. This line simply prints "Hello again" and then returns. To stop this timer we can simply execute:
TIMER 1 STOP