void updateButtonStates() { // Read the state of each button and update the boolean array bool pressed = false; for (int i = 0; i < numButtons - 1; ++i) { pressed = digitalRead(buttonPins[i]) == LOW; if (pressed != buttonStates[i]) { if (!buttonStates[i]) { //Button down Serial.print("[INFO] keydown="); Serial.println(i); handleButtonDown(i); } else { //Button up Serial.print("[INFO] keyup="); Serial.println(i); handleButtonUp(i); } buttonStates[i] = pressed; } } //Read the analog emulated pins int a0Valu = analogRead(A0); pressed = (a0Valu < 1000); if (pressed != buttonStates[4]) { if (!buttonStates[4]) { //Button down Serial.println("[INFO] keydown=4"); handleButtonDown(4); } else { //Button up Serial.println("[INFO] keyup=4"); handleButtonUp(4); } buttonStates[4] = pressed; } } // Function to reset all outputs to 0 void resetOutputs() { // Shift in 8 zeros (all outputs off) for (int i = 0; i < 8; ++i) { digitalWrite(SER_PIN, LOW); digitalWrite(SRCLK_PIN, HIGH); delay(1); // Optional: Adjust delay if needed digitalWrite(SRCLK_PIN, LOW); } // Latch the data to the output pins digitalWrite(RCLK_PIN, HIGH); delay(1); // Optional: Adjust delay if needed digitalWrite(RCLK_PIN, LOW); } //Handle button down and up events, index start from 0 void handleButtonDown(int index) { } void handleButtonUp(int index) { //Generate the base URL from ip and port String baseURL = "http://" + target_ip.toString() + ":" + String(target_port); if (index == 0){ baseURL += "/toggle?relay=0"; }else if (index == 1){ baseURL += "/toggle?relay=1"; }else if (index == 2){ baseURL += "/toggle?relay=2"; }else if (index == 3){ baseURL += "/toggle?relay=3"; }else if (index == 4){ resolveTargetRelayIP(); return; } Serial.println("Sending request to: " + baseURL); GetRequest(baseURL); }