void setup() {
Serial.begin(115200);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D10, INPUT_PULLUP); //set as INPUT_PULLUP, which mean active the pullup resistor inside the microcontroller, avoiding the short circuit when the button is pressed.
pinMode(D9, INPUT_PULLUP); //when pin is set as pull up, the digital read result will always be 1
pinMode(D8, INPUT_PULLUP); //and only become 0 when the button is pressed.
}
void loop() {
if (digitalRead(D10)==0){digitalWrite(D2, HIGH);} //
else { digitalWrite(D2, LOW);}
if (digitalRead(D9)==0){digitalWrite(D3, HIGH);}
else { digitalWrite(D3, LOW);}
if (digitalRead(D8)==0){digitalWrite(D4, HIGH);}
else { digitalWrite(D4, LOW);}
}
Loading
xiao-esp32-c3
xiao-esp32-c3