pololu / pololu-buzzer-arduino

C++ library for the Arduino IDE that allows you to play notes and songs on a buzzer.
MIT License
6 stars 4 forks source link

Optional "Turn Buzzer Off" #2

Open magicbycalvin opened 7 years ago

magicbycalvin commented 7 years ago

When using the Pololu Zumobot 32U4 example codes, some of them incorporate the buzzer sound. This can be a nuisance at times. It would be nice if there were a flag that could be changed or a simple call made at the beginning of the code that would disable all buzzer sounds. It would be a much more elegant solution than either physically disabling the buzzer or searching through the code and commenting out or deleting all buzzer calls.

Thank you for your time and consideration!

DavidEGrayson commented 7 years ago

Yes, that could be useful, and I'll keep this issue open so we can consider adding it the next time we work on this library.

In the mean time, here's something you could try on a Zumo 32U4 or any other ATmega32U4-based board. Near the beginning of your setup function, put this code:

buzzer.init();
DDRD &= ~(1 << 7);  // Disable buzzer output

This will disable the I/O pin used for buzzer output. The buzzer code and its timer will still run as usual, but the output should be disabled and get pulled down by the board. Calling buzzer.init() is important because if you don't do that then the buzzer library will initialize itself later when your code plays some notes.

magicbycalvin commented 7 years ago

Thank you for the quick reply sir! I will use those lines of code you have provided for the time being.