diff --git a/vulpes/src/main.cpp b/vulpes/src/main.cpp index 3f84526..15bcf5d 100644 --- a/vulpes/src/main.cpp +++ b/vulpes/src/main.cpp @@ -46,7 +46,7 @@ const char index_html[] PROGMEM = R"rawliteral(
- inputInt (current value %inputInt%): + Seconds between flash (current value %inputInt%):

@@ -56,24 +56,32 @@ const char index_html[] PROGMEM = R"rawliteral( )rawliteral"; +// Auxiliary variables to store the current output state +String output26State = "off"; +String output27State = "off"; + +// Assign output variables to GPIO pins +const int output26 = 26; +const int output27 = 27; + void notFound(AsyncWebServerRequest *request) { request->send(404, "text/plain", "Not found"); } String readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\r\n", path); + //Serial.printf("Reading file: %s\r\n", path); File file = fs.open(path, "r"); if(!file || file.isDirectory()){ Serial.println("- empty file or failed to open file"); return String(); } - Serial.println("- read from file:"); + //Serial.println("- read from file:"); String fileContent; while(file.available()){ fileContent+=String((char)file.read()); } file.close(); - Serial.println(fileContent); + //Serial.println(fileContent); return fileContent; } @@ -109,6 +117,14 @@ String processor(const String& var){ void setup() { Serial.begin(115200); + + // Initialize the output variables as outputs + pinMode(output26, OUTPUT); + pinMode(output27, OUTPUT); + // Set outputs to LOW + digitalWrite(output26, LOW); + digitalWrite(output27, LOW); + // Initialize SPIFFS #ifdef ESP32 if(!SPIFFS.begin(true)){ @@ -166,6 +182,21 @@ void setup() { } void loop() { + // Read seconds from file + int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt(); + // Blink LED according to seconds entered + if (yourInputInt > 0) { + Serial.println("GPIO 26 on"); + output26State = "on"; + digitalWrite(output26, HIGH); + delay(yourInputInt * 1000); + Serial.println(yourInputInt); + Serial.println("GPIO 26 off"); + output26State = "off"; + digitalWrite(output26, LOW); + delay(yourInputInt * 1000); + } + // // To access your stored values on inputString, inputInt, inputFloat // String yourInputString = readFile(SPIFFS, "/inputString.txt"); // Serial.print("*** Your inputString: ");