Here is an example application which creates a reaction game. The Cricket will randomly beep, and you have to hit a switch as soon as you can after you hear the beep. The Cricket then measures the delay between the beep and your reaction.
The Cricket's 4-digit display is used. After each try, your delay score is shown on the display.
In the example, you are given ten tries, and the Cricket displays your average performance at the end.
The random function is used. This produces a randomized value from 0 to 32767. It is used in conjunction with the remainder/modulus operator to produce a random value between 0 and 39.
global [delay total] to reaction settotal 0 repeat 10 [ wait 10 + (random % 40) ; wait from 1 to 5 seconds resett beep waituntil [switcha] setdelay timer display delay settotal total + delay ] display total / 10 end to display :n bsend $110 bsend 0 bsend high-byte :n bsend low-byte :n end