C4 — Digital inputs

Level 2 — Use variables

Complete the challenge

void setup() {
    pinMode(8, OUTPUT);       // set up pin 8 as an output.
    pinMode(6, INPUT_PULLUP); // set up pin 6 as an input.
}

void loop() {
    if (digitalRead(6) == HIGH) {  // check if the input is HIGH
        digitalWrite(8, HIGH);    // turn the LED on
    } else {
        digitalWrite(8, LOW);     // turn the LED off
    }
}
int inputPin = 6;
int ledPin = 8;

void setup() {
    pinMode(ledPin, OUTPUT);         // set up pin "ledPin" as an output.
    pinMode(inputPin, INPUT_PULLUP); // set up pin "inputPin" as an input.
}

void loop() {
    if (digitalRead(inputPin) == HIGH) {  // check if the input is HIGH
        digitalWrite(ledPin, HIGH);    // turn the LED on
    } else {
        digitalWrite(ledPin, LOW);     // turn the LED off
    }
}

Change the value of inputPin and ledPin.

Edit the lines int inputPin = 6; and int ledPin = 8;

Claim your achievement