Hi,
I am trying to find out the best command/function i can use to work with my piezo buzzer i am using. I want to be able to use PWM Features so the tone command is out of the picture which is a shame because it is the simplest one out of the options.
I am trying to get the buzzer to work with a digitalWrite function, but I cannot seem to get anywhere with it. It just makes a tiny buzzing sound. I was thinking it was because there was no frequency defined to that command but i am not sure how to do it with that command.
After this attempt i had tried the analogWrite function. This had worked but seems quite quiet, and wasnt sure how to change or find out the frequency it is running at.
There is the toneAC and toneAC2 library. They are nominally functionally identical except toneAC2 uses timer2 which may solve your PWM feature conflict.
blinker mrTone(3,2.5,5); // Pin number, pulseMs, periodMs
timeObj toneTimer(1000); // Timer for xMs
void setup(void) {
mrTone.setOnOff(true); // Fire up the tone.
}
void loop(void) {
idle(); // Run background things, like the blinker.
if (toneTimer.ding()) { // If the timer has expited (**ding!**)..
mrTone.setOnOff(false); // Shut off the tone.
}
}
You'll need to grab LC_baseTools from the library manager to compile it.
ToneAC uses a timer to generate the output signal without program involvement after it is configured. In this sense it is the same as Tone. However, there is a second version of the library, ToneAC2 that uses a different timer.
So if your issue is a conflict between the timer used by Tone, ToneAC2 is a readily available library that may resolve the issue by virtue of using a different timer.