#include <Arduino.h>

// Use digital pin 2 to read the switch.
const uint8_t SWITCH_PIN = 2;

// Set up the built-in LED and enable the switch input pull-up.
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  // The internal pull-up means an open switch reads HIGH and a closed-to-ground switch reads LOW.
  pinMode(SWITCH_PIN, INPUT_PULLUP);
}

// This one line reads the switch and updates the LED immediately.
void loop() {
  // ?: is a compact if/else: when the switch reads LOW, output HIGH; otherwise output LOW.
  digitalWrite(LED_BUILTIN, digitalRead(SWITCH_PIN) == LOW ? HIGH : LOW);
}
