#include <Arduino.h>

// These named constants identify the LED output and the two button inputs.
const uint8_t LED_PIN = 5;
const uint8_t ON_BUTTON = 9;
const uint8_t OFF_BUTTON = 8;

// Configure the LED as OUTPUT and the buttons as INPUT_PULLUP.
void setup() {
  pinMode(LED_PIN, OUTPUT);
  // INPUT_PULLUP uses an internal resistor: pressed = LOW, released = HIGH.
  pinMode(ON_BUTTON, INPUT_PULLUP);
  pinMode(OFF_BUTTON, INPUT_PULLUP);
}

// Read each button repeatedly. The LED remembers the last button command.
void loop() {
  // If the ON button is pressed, switch the LED on.
  if (digitalRead(ON_BUTTON) == LOW) digitalWrite(LED_PIN, HIGH);
  // If OFF is pressed, switch it off. This second if runs independently.
  if (digitalRead(OFF_BUTTON) == LOW) digitalWrite(LED_PIN, LOW);
}
