Controlling a buzzer
We are going to write a very simple buzzer library. We only want the buzzer to make any sound, regardless of the pitch. We start off by adding the buzzer to the circuit. To do so, follow these steps:
- Connect D4 from the Arduino to A31 on the breadboard using a jumper wire.
- Use a 100 Ohm resistor to connect E31 with G31 on the breadboard.
- Connect the VCC pin from the buzzer with J31.
- Connect the GND pin to GND on the power bus.
The circuit should now look like the following figure:
As we have now added the buzzer to the circuit, we can now start to write our library.
Writing a buzzer library
The buzzer library will have two functions: Configure()
, which sets up the pin, and the Beep()
function, which will make the sound.
We start off by creating a new folder named buzzer
inside the Chapter04
folder. Inside the new folder, create a file named...