ezBuzzer Library - Melody Example
This example uses a piezo buzzer:
- Plays a melody once on background each time a button is pressed
- Stops playing a melody when another button is pressed
- Without using delay() function, this is a non-blocking example
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
About ezBuzzer Library
- Refer to Arduino - ezBuzzer Library Reference
- Install ezBuzzer library. See How To
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- On Arduino IDE, Go to File Examples ezBuzzer Melody example
- Click Upload button on Arduino IDE to upload code to Arduino
- Press and release the START button, You will hear "Jingle Bells" song
- Press and release the STOP button, The song is stopped immediately
If you do not press STOP button, the song will be played to the end of song.
Read the line-by-line explanation in comment lines of source code!
※ NOTE THAT:
The above example code demonstrates how to use the ezBuzzer library to make a beep on Piezo Buzzer each time button is pressed. In practice, You may need to debounce for the button. Debouncing for the button is not easy for beginners. Fortunately, thanks to the ezButton library, We can do it easily.