// Grade 8: keep your existing, teacher-checked LED circuit and resistor. // Replace -1 with the LED GPIO from your saved working sketch. // GPIO numbers are not physical header positions. Never put 5 V on a GPIO. // Unplug USB before changing wires. Ask the teacher to check before power. const int LED_PIN = -1; // true: HIGH turns your LED on. false: LOW turns your LED on. // The teacher must check this setting against your known working circuit. const bool LED_ACTIVE_HIGH = true; static_assert(LED_PIN >= 0, "Set LED_PIN to your teacher-checked working LED GPIO."); bool ledOn = false; void showLed() { digitalWrite(LED_PIN, (ledOn == LED_ACTIVE_HIGH) ? HIGH : LOW); } void setup() { Serial.begin(115200); // Set the desired off level before enabling the output. showLed(); pinMode(LED_PIN, OUTPUT); showLed(); Serial.println("Ready: 1 = on, 0 = off. LED starts off."); } void loop() { if (Serial.available() == 0) return; char command = Serial.read(); if (command == '\n' || command == '\r') return; if (command == '1') { ledOn = true; } else if (command == '0') { ledOn = false; } else { Serial.println("Invalid command: send 1 or 0. LED state unchanged."); return; } showLed(); Serial.println(ledOn ? "LED ON" : "LED OFF"); }