#include <Arduino.h>

// D2->button->GND; D8->resistor->LED->GND.
// Button input on D2 and LED output on D8 are two different jobs.
const int buttonPin = 2;
const int ledPin = 8;

void setup() {
  // INPUT_PULLUP activates an internal resistor. Released reads HIGH; pressed to GND reads LOW.
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // if runs its block only when the expression is true. == compares values; LOW means pressed
  // here.
  if (digitalRead(buttonPin) == LOW) {
    digitalWrite(ledPin, HIGH); // LOW means pressed.
  // else handles the other case: button released, so the LED should be off.
  } else {
    digitalWrite(ledPin, LOW);
  }
}
