const int buzzer_pin = 12;
const int button1_pin = 14;
unsigned long time_db = 0UL;
bool debounce = false;
bool buzz = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(button1_pin, INPUT_PULLUP);
pinMode(buzzer_pin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (millis() - time_db > 200){
time_db = millis();
debounce = true;
}
if (digitalRead(button1_pin) == LOW && debounce == true){
debounce = false;
buzz = !buzz;
}
if (buzz) {
digitalWrite(buzzer_pin, HIGH);
Serial.println("On");
}
else {
digitalWrite(buzzer_pin, LOW);
Serial.println("Off");
}
}