Blink LED according to time entered.
This commit is contained in:
parent
df8e3af432
commit
76ef0b129f
|
@ -46,7 +46,7 @@ const char index_html[] PROGMEM = R"rawliteral(
|
||||||
<input type="submit" value="Submit" onclick="submitMessage()">
|
<input type="submit" value="Submit" onclick="submitMessage()">
|
||||||
</form><br>
|
</form><br>
|
||||||
<form action="/get" target="hidden-form">
|
<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()">
|
<input type="submit" value="Submit" onclick="submitMessage()">
|
||||||
</form><br>
|
</form><br>
|
||||||
<form action="/get" target="hidden-form">
|
<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>
|
<iframe style="display:none" name="hidden-form"></iframe>
|
||||||
</body></html>)rawliteral";
|
</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) {
|
void notFound(AsyncWebServerRequest *request) {
|
||||||
request->send(404, "text/plain", "Not found");
|
request->send(404, "text/plain", "Not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
String readFile(fs::FS &fs, const char * path){
|
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");
|
File file = fs.open(path, "r");
|
||||||
if(!file || file.isDirectory()){
|
if(!file || file.isDirectory()){
|
||||||
Serial.println("- empty file or failed to open file");
|
Serial.println("- empty file or failed to open file");
|
||||||
return String();
|
return String();
|
||||||
}
|
}
|
||||||
Serial.println("- read from file:");
|
//Serial.println("- read from file:");
|
||||||
String fileContent;
|
String fileContent;
|
||||||
while(file.available()){
|
while(file.available()){
|
||||||
fileContent+=String((char)file.read());
|
fileContent+=String((char)file.read());
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
Serial.println(fileContent);
|
//Serial.println(fileContent);
|
||||||
return fileContent;
|
return fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +117,14 @@ String processor(const String& var){
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
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
|
// Initialize SPIFFS
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if(!SPIFFS.begin(true)){
|
if(!SPIFFS.begin(true)){
|
||||||
|
@ -166,6 +182,21 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
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
|
// // To access your stored values on inputString, inputInt, inputFloat
|
||||||
// String yourInputString = readFile(SPIFFS, "/inputString.txt");
|
// String yourInputString = readFile(SPIFFS, "/inputString.txt");
|
||||||
// Serial.print("*** Your inputString: ");
|
// Serial.print("*** Your inputString: ");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user