// GLOBALS & CONSTANTS
int LED_PIN = 7;
int BTN_PIN = 8;
void setup() {
pinMode(LED_PIN, OUTPUT);
// INPUT_PULLUP necessary for the button, since there’s no external resistor
pinMode(BTN_PIN, INPUT_PULLUP);
}
void loop() {
int btn_val = digitalRead(BTN_PIN);
// Since BTN_PIN uses INPUT_PULLUP, if it's not pressed, the value will be 1, meaning it's reverse.
// (Remember the second example from the first lab, where the values became 0 only if you pressed the button)
// Perform a XOR operation to "toggle" the value
int led_val = btn_val ^ 1;
// Write the value to the LED
digitalWrite(LED_PIN, led_val);
}