buzzer.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <NonBlockingRtttl.h>
  4. /* class abstracts underlying RTTTL library
  5. Just a simple imlementation to start. At the moment use same
  6. melody for message and discovery
  7. Suggest enum type for different sounds
  8. - on message
  9. - on discovery
  10. TODO
  11. - make message ring tone configurable
  12. */
  13. class genericBuzzer
  14. {
  15. public:
  16. void begin(); // set up buzzer port
  17. void play(const char *melody); // Generic play function
  18. void loop(); // loop driven-nonblocking
  19. void startup(); // play startup sound
  20. void shutdown(); // play shutdown sound
  21. bool isPlaying(); // returns true if a sound is still playing else false
  22. void quiet(bool buzzer_state); // enables or disables the buzzer
  23. bool isQuiet(); // get buzzer state on/off
  24. private:
  25. // gemini's picks:
  26. const char *startup_song = "Startup:d=4,o=5,b=160:16c6,16e6,8g6";
  27. const char *shutdown_song = "Shutdown:d=4,o=5,b=100:8g5,16e5,16c5";
  28. bool _is_quiet = true;
  29. };