5. You want to detect if a switch connected to pin 3 is pressed, but the switch is wired so it connects the pin to GND when pressed (active LOW). Which code snippet correctly reads the switch state and prints "Pressed" or "Not Pressed" accordingly?
A)
pinMode(3, INPUT);
if (digitalRead(3) == HIGH) {
Serial.println("Pressed");
} else {
Serial.println("Not Pressed");
}
B)
pinMode(3, INPUT);
if (digitalRead(3) == LOW) {
Serial.println("Pressed");
} else {
Serial.println("Not Pressed");
}
C)
pinMode(3, OUTPUT);
if (digitalRead(3) == LOW) {
Serial.println("Pressed");
} else {
Serial.println("Not Pressed");
}
D)
pinMode(3, INPUT_PULLUP);
if (digitalRead(3) == HIGH) {
Serial.println("Pressed");
} else {
Serial.println("Not Pressed");
}