/* * HelloWorldWeek8.ino * XIAO ESP32-C3 on revised HelloWorld board (JLCPCB) * * Button on D7 — internal pull-up (reads LOW when pressed) * LEDs on D8 and D9 — toggle on each button press */ #define SWITCH_PIN D7 #define LED1_PIN D8 #define LED2_PIN D9 bool ledState = false; bool lastButtonState = HIGH; void setup() { Serial.begin(115200); pinMode(SWITCH_PIN, INPUT_PULLUP); pinMode(LED1_PIN, OUTPUT); pinMode(LED2_PIN, OUTPUT); digitalWrite(LED1_PIN, LOW); digitalWrite(LED2_PIN, LOW); } void loop() { bool currentButtonState = digitalRead(SWITCH_PIN); if (lastButtonState == HIGH && currentButtonState == LOW) { delay(50); ledState = !ledState; digitalWrite(LED1_PIN, ledState ? HIGH : LOW); digitalWrite(LED2_PIN, ledState ? HIGH : LOW); Serial.println(ledState ? "LED ON" : "LED OFF"); } lastButtonState = currentButtonState; delay(10); }