Red Pitaya Blog

Home » , »

Making A buzzer buzz

This example introduces the Extension board, a sensor and Dashboard Blocks. An on screen switch is used to turn a buzzer ‘ON’ and ‘OFF’. Please use the wiring and block diagrams below for guidance.

 

Step 1

Connect the extension module to Red Pitaya.
Connect the Buzzer to the CN12 connector on the extension module, which is part of a group of connectors providing digital input/output signals.

Step 2

To sound the buzzer we need Indicators > Buzzer > Set buzzer on pin block. We can set it to ‘HIGH’ (buzzing) or ‘LOW’ (silent). We also have to specify to which data signal the buzzer is connected, in out example this is ‘D0’, the first o f 16 digital IO (input/output) signals.
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.

Categories
Subscribe to our newsletter

Related Posts