Blink LED according to time entered.

This commit is contained in:
mattbk 2023-08-22 14:13:47 -05:00
parent df8e3af432
commit 76ef0b129f

View File

@ -46,7 +46,7 @@ const char index_html[] PROGMEM = R"rawliteral(
<input type="submit" value="Submit" onclick="submitMessage()">
</form><br>
<form action="/get" target="hidden-form">
inputInt (current value %inputInt%): <input type="number " name="inputInt" value = %inputInt%>
Seconds between flash (current value %inputInt%): <input type="number " name="inputInt" value = %inputInt%>
<input type="submit" value="Submit" onclick="submitMessage()">
</form><br>
<form action="/get" target="hidden-form">
@ -56,24 +56,32 @@ const char index_html[] PROGMEM = R"rawliteral(
<iframe style="display:none" name="hidden-form"></iframe>
</body></html>)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: ");