void setup() {
pinMode(LED_BUILTIN, OUTPUT); // Set the built-in LED as an output
pinMode(2, INPUT_PULLUP); // Set pin 2 as input with internal pull-up resistor
}
void ledon() {
digitalWrite(LED_BUILTIN, HIGH); // Turn on the LED
}
void ledoff() {
digitalWrite(LED_BUILTIN, LOW); // Turn off the LED
}
void loop() {
(digitalRead(2) == LOW) ? ledon() : ledoff(); // Ternary operator to decide LED state
}