#include <Arduino.h>

// Same D2 button and D8 LED; set PlatformIO Monitor 9600 baud.
const int buttonPin = 2;
const int ledPin = 8;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  // Start the USB Serial connection at 9600 baud; set the Serial Monitor to match.
  Serial.begin(9600);
}

void loop() {
  // Store the latest HIGH or LOW button reading in an int variable.
  int reading = digitalRead(buttonPin);
  // print() sends readable text without adding a new line.
  Serial.print("Button: ");
  // The ? : operator selects one of two messages; println() adds a line break.
  Serial.println(reading == LOW ? "PRESSED (LOW)" : "RELEASED (HIGH)");
  // The same choice also controls the LED: on when pressed, off when released.
  digitalWrite(ledPin, reading == LOW ? HIGH : LOW);
  // Wait 100 ms between reports so the Serial Monitor is easier to read.
  delay(100);
}
