Arduino click sound for my Adafruit ESP32 assistive touch switch
I used an optocoupler instead of a relay but I still wanted a mechanical click sound for my assistive touch switch. It's based on an Adafruit Feather Esp32 Huzzah and i use a 8 ohm speaker with an 150 ohm resistor in between.
Thanking El_supremo in Arduino forum for coding inspiration
https://forum.arduino.cc/t/tick-tock-sound-from-a-piezoelectric-speaker/288494
----------------------------------
CODE SNIPPET:
// Play a sound if button is pressed (was previously NOT pressed)
if(pressed == false){
tone(buzzer, 5000, 5);
tone(buzzer, 500, 5);
}
digitalWrite(outputA,HIGH);
pressed = true;
}else{
// Play a sound when button was released
if(pressed == true){
tone(buzzer, 500, 5);
tone(buzzer, 5000, 5);
}
digitalWrite(outputA, LOW);
pressed = false;
delay(50)