You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Macros - act like constant variables (cannot be changed).// The compiler will replace these in the code with their values.
#defineLEDL7
#defineLEDC6
#defineLEDR5
#defineBTN1// btn should be true if the button is pressed and false otherwisebool btn = false;
// btnAck should be the same value as btn AFTER the code has run one cycle// this will allow us to only run code once when the button is pressed or// released instead of constantly.bool btnAck = false;
voidsetup()
{
pinMode(LEDR, OUTPUT);
pinMode(LEDC, OUTPUT);
pinMode(LEDL, OUTPUT);
pinMode(BTN, INPUT_PULLUP);
}
voidloop()
{
// Update btnAck to be the value of btn
btnAck = btn;
// Set btn to true if the button is currently being pressed
btn = !digitalRead(BTN);
// If the button is pressed AND btnAck has not been updatedif (btn && !btnAck) {
digitalWrite(LEDR, HIGH);
delay(1000);
digitalWrite(LEDC, HIGH);
delay(1000);
digitalWrite(LEDL, HIGH);
}
// Else If the button is NOT pressed AND btnAck has not been updatedelseif (!btn && btnAck) {
digitalWrite(LEDR, LOW);
delay(1000);
digitalWrite(LEDC, LOW);
delay(1000);
digitalWrite(LEDL, LOW);
}
}