Hello,
I'm using a Teensy 3.5 with a piezo speaker that beeps as expected when connected to power through USB. However, when I remove the USB and power it via batteries, sometimes the speaker beeps but usually it doesn't.
The setup is simply
and the routine is
I'd be grateful for hints!
I'm using a Teensy 3.5 with a piezo speaker that beeps as expected when connected to power through USB. However, when I remove the USB and power it via batteries, sometimes the speaker beeps but usually it doesn't.
The setup is simply
Code:
pinMode(speakerPin, OUTPUT);
and the routine is
Code:
void Beep(int pitch, int duration)
{
for (int j=1; j < duration; j++)
{
digitalWrite(speakerPin, HIGH); // send 3.3 volts to the speaker pin
delayMicroseconds(pitch);
digitalWrite(speakerPin, LOW); // remove voltage from the speaker pin
delayMicroseconds(pitch);
}
}
I'd be grateful for hints!