3. ESP32 GPIO Usage and Applications

Question.2

Kevin has built the following circuit. When will LED glow?

 


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

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

Select Answer