C4 — Digital inputs
Level 1 — Use a digital input
Complete the challenge
Your entire setup()
function should look like this:
void setup() {
pinMode(6, INPUT_PULLUP); // set up pin 6 as an input.
}
Your entire setup()
function should look like this:
void setup() {
pinMode(6, INPUT_PULLUP); // set up pin 6 as an input.
pinMode(8, OUTPUT); // set up pin 8 as an output.
}
or like this:
void setup() {
pinMode(8, OUTPUT); // set up pin 8 as an output.
pinMode(6, INPUT_PULLUP); // set up pin 6 as an input.
}
Your entire loop()
function should look like this:
void loop() {
if (digitalRead(6) == HIGH) { // check if the button is pressed
digitalWrite(8, HIGH); // turn the LED on if the input is on
} else {
digitalWrite(8, LOW); // turn the LED off if the input is not on
}
}