Active, not passive
The buzzer on this shield is an active buzzer on pin 3: it takes a plain HIGH or LOW and plays one fixed pitch. LOW makes noise, HIGH is silent. You cannot play tunes with it, but it is perfect for alarms and alerts.
Two ways to use it
- Direct.
digitalWrite(BEEPER_PIN, LOW)while a button is held, HIGH when released. That is whatloop()does below. - Library.
MFS.beep()gives a short beep. With arguments,MFS.beep(on, off, cycles, loops, loopDelay)builds patterns. Every time value is in units of 10 ms, soMFS.beep(5, 5, 4, 3, 50)means: on 50 ms, off 50 ms, four times, repeated three times, with 500 ms between repeats.
The library needs Timer1.initialize() followed by MFS.initialize(&Timer1) in setup(). The TimerOne library is what lets the beeper pattern run in the background while your loop keeps going.
Beeper: direct and library patterns