Timing has two jobs: pause a straightforward sequence, or measure elapsed time. Use events when code should react later without holding the foreground evaluation.
Blink With A Delay
repeat 3 [
led.on:
ms: 75
led.off:
ms: 75
]
ms accepts a nonnegative integer, polls for Ctrl-C once per millisecond, and
returns nil. Later expressions in the same word do not run until the delay
finishes.
Measure A Short Span
started is millis:
ms: 25
finished is millis:
elapsed is 0
set elapsed to finished - started
| Word | Result | Current 32-bit wrap period |
|---|---|---|
ms | nil | not applicable |
millis | Int | about 12.4 days |
micros | Int | about 17.9 minutes |
The visible clocks wrap at the tagged integer ceiling. Short modular deltas across the wrap remain useful; do not treat either clock as a wall-clock date or an indefinitely increasing persisted counter.
Delay, Timer Event, Or Signal Hardware?
- Use
msfor a short, linear sequence. - Use
afteroreverywhen work should run at a later safe point while the prompt remains live. - Use
trace.*orpulse.*when edge timing must be captured or emitted with 100-nanosecond hardware quantization.
Continue with Events or Digital signals .