The Switch block from the Dashboard generates a named signal each time it is toggled, additionally is sends the ‘ON’ and ‘OFF’ status aft er the change. To receive this signal the Signal > On receive signal [] with signal value [] Do block is used. The switch and the receiver must use the same signal name. When the switch is toggled the receiver will execute the code inside the block, but first it will set the variable ‘buzz_state’ to the state of the switch. The Program > Logic > if [] do [] else [] block is used to turn ‘HIGH’ the buzzer only if the switch is set to ‘ON’, else the buzzer will be turned to ‘LOW’.

An important programming concept introduced in this example is a ‘variable’. Variables are used by programs to memorize numbers, ON/OFF states, text and many other things. When choosing a name for a variable, find something meaningful, so the name will remind you of the variable’s purpose. The same program can be used to control an LED, try to add a Set LED block, so it will shine while the buzzer is silent.