-
Notifications
You must be signed in to change notification settings - Fork 55
Timers
aanon4 edited this page Sep 22, 2014
·
1 revision
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
. Current four timers are supported. Each time 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 (e.g. execute every 5 seconds) or just run once (e.g. execute after 5 seconds and then stop).
For example:
10 TIMER 1, 2000 REPEAT GOSUB 1020
...
1020 PRINT "Hello"
1030 RETURN
The above example sets up timer 1. Every 2000 milliseconds, repeatedly, it will run the subroutine at line 1020. This line simply prints "Hello" and then finishes. To stop this timer we can simply execute:
TIMER 1 STOP