How to use buzzer without blocking other code
How can I play melody using Arduino and buzzer WITHOUT blocking other code? Example from Arduino IDE uses the delay() function. This blocks other code. How can I solve it?
You can solve the above issue by using ezBuzzer Library. This library allows you to generate a beep, play a melody, stop playing a melody without using delay() function. In other words, this library is non-blocking. All works are done on background.
You can refer to the below example. The example do:
- Plays a melody once on background each time a button is pressed
- Stops playing a melody when another button is pressed
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
|1||×||(Optional) 9V Power Adapter for Arduino|
|1||×||(Recommended) Screw Terminal Block Shield for Arduino Uno|