#include #include // --- Pin definition (XIAO ESP32-C6) --- #define BUTTON1 D4 #define BUTTON2 D6 // Create web server on port 80 WebServer server(80); // --- Variables to store the previous button states --- int lastState1; int lastState2; // --- Function to generate the HTML page --- String getHTML() { int b1 = digitalRead(BUTTON1); int b2 = digitalRead(BUTTON2); String html = ""; html += ""; html += ""; html += ""; html += "

BENI ALVAREZ PCB Buttons

"; html += "

XIAO ESP32-C6

"; // In this PCB: // LOW = button released // HIGH = button pressed html += "

D4: "; html += (b1 == HIGH) ? "PRESSED" : "RELEASED"; html += "

"; html += "

D6: "; html += (b2 == HIGH) ? "PRESSED" : "RELEASED"; html += "

"; html += ""; return html; } // --- Handle root URL --- void handleRoot() { server.send(200, "text/html", getHTML()); } void setup() { Serial.begin(115200); delay(1000); // Configure button pins // NOTE: the real logic of this PCB is active HIGH: // released = LOW, pressed = HIGH pinMode(BUTTON1, INPUT_PULLUP); pinMode(BUTTON2, INPUT_PULLUP); // Small delay to let the inputs stabilize delay(50); // Read the real initial state of each button lastState1 = digitalRead(BUTTON1); lastState2 = digitalRead(BUTTON2); // Create Wi-Fi Access Point WiFi.softAP("XIAO_ESP32"); Serial.print("AP IP address: "); Serial.println(WiFi.softAPIP()); // Start web server server.on("/", handleRoot); server.begin(); Serial.println("Web server started"); } void loop() { // Handle incoming HTTP requests server.handleClient(); // Read current states int currentState1 = digitalRead(BUTTON1); int currentState2 = digitalRead(BUTTON2); // Detect state change on BUTTON1 if (currentState1 != lastState1) { if (currentState1 == HIGH) { Serial.println("D4 PRESSED"); } else { Serial.println("D4 RELEASED"); } lastState1 = currentState1; delay(20); // simple debounce } // Detect state change on BUTTON2 if (currentState2 != lastState2) { if (currentState2 == HIGH) { Serial.println("D6 PRESSED"); } else { Serial.println("D6 RELEASED"); } lastState2 = currentState2; delay(20); // simple debounce } }