I wrote a code that has multiple voids and in one that reads button input, when the button is pressed i want that the buzzer beeps for 200ms, but i don't want to use delay because it stops the uc, so i made a idk exactly what's called but a function that switches the state every 200ms and returns value which i then write to buzzer pin, but i'm not sure how to make it so the function only executes when a button is pressed
on_off_button_state = digitalRead(ON_OFF); // reads button state and saves it in a variable
if (on_off_button_state == 1) // if button on_off is pressed
{
on_off_count++;
digitalWrite(BUZZER, buzzer_state);
Serial.print("ON/OFF BUTTON PRESSED!");
if (on_off_count == 1 && on_off_button_state == 1)
{
on_off_count = 0;
}
}
I'm certain I've seen this concept completely coded in other posts on this forum. OP, have you spent time searching for it here? You have a low recent read time.
The whole code is pretty long >800lines and is split into multiple files
I changed the code to
set_button_state = digitalRead(SET); // reads button state and saves it in a variable
if (set_button_state == 1) // if button set is pressed
{
set_count++;
Serial.print("SET BUTTON PRESSED!");
buzzer();
if (set_count == 1 && set_button_state == 1)
{
set_count = 0;
}
}