#include #include #include #include // This code demonstrates how to use the cards ESPMegaPRO espmega = ESPMegaPRO(); AnalogCard analogCard = AnalogCard(); void inputCallback(uint8_t pin, bool state) { Serial.print("Input "); Serial.print(pin); Serial.print(" changed to "); Serial.println(state); } void printInputs() { for (int i = 0; i < 16; i++) { Serial.print("Input "); Serial.print(i); Serial.print(": "); Serial.print(espmega.inputs.digitalRead(i)); Serial.println(); } } void setup() { // Instantiate ESPMega espmega.begin(); Serial.println("ESPMega initialized"); // Read all the inputs and print them printInputs(); // Turn on all the outputs for (int i = 0; i < 16; i++) { espmega.outputs.digitalWrite(i, true); } // Set the debounce time for all inputs to 200ms for (int i = 0; i < 16; i++) { espmega.inputs.setDebounceTime(i, 200); } // Register the callback function espmega.inputs.registerCallback(inputCallback); // Install the analog card Serial.println("Installing analog card"); if (espmega.installCard(0, &analogCard)) { Serial.println("Analog card installed"); } else { Serial.println("Failed to install analog card"); } } unsigned long previousMillis = 0; const unsigned long interval = 1000; // 1 second void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; printInputs(); } espmega.loop(); }