2. Arduino GPIO Programming Basics

Question.6

Sarah connected an LED and a button to Arduino, As shown in given circuit diagram. She wrote the following code. What will happen to the LED when the button is pressed?

void setup() {
  pinMode(9, OUTPUT);
  pinMode(4, INPUT_PULLUP);
}

void loop() {
  int buttonState = digitalRead(4);
  if (buttonState == HIGH) {
    digitalWrite(9, HIGH);
  } else {
    digitalWrite(9, LOW);
  }
}

Select Answer