Cricket Tutorial — Switch Sensor and Waituntil Command

Now that we know how to define procedures, let's learn a simple way to use a pushbutton sensor (also known as a touch sensor).

Start off by clicking on the Click for Sensor A box, and select Push Sensor. Now click on the sensor itself. It should push in and turn green while you are clicking on it (indicating “true”) and spring out and turn red when you release the mouse (indicating “false”).

                     Run Button ^

Type the procedure on the right into the Procedure window or .

Then, type test into the Run This line, click the Download button, and then click on the Cricket's Run Button.

to test
a, on
waituntil [switcha]
a, off
What happens? The procedure runs and turns on the motor. Then, the waituntil command executes, and waits until the touch sensor is pressed. If it's not pressed, it checks the sensor again, and again, and again. Meanwhile, the motor keeps running.

Now, click on the touch sensor. The sensor becomes true, waituntil finishes, and the Cricket executes the a, off command. The motor should turn off!

If you want to try it again, click on the Cricket's Run Button to restart the procedure.

BACK: Programming the Cereal Dispenser

UP to index

NEXT: Intro to Cereal Dispenser, Stage 2