Add function to toggle gpio 26.

This commit is contained in:
mattbk 2023-08-26 21:08:35 -05:00
parent 5b9e369e7a
commit 917dd85465

View File

@ -75,6 +75,18 @@ bool toggle_led(void *) {
return true; // keep timer active? true
}
// Toggle GPIO pin (LED or relay)
bool toggle_gpio_26(void *) {
if(output26State == "off"){
output26State = "on";
digitalWrite(output26, HIGH);
} else {
output26State = "off";
digitalWrite(output26, LOW);
}
return true; // keep timer active? true
}
// defaults
// String yourInputString;
// int yourInputInt;
@ -136,8 +148,10 @@ void setup() {
// Timer example, blink main LED
pinMode(LED_BUILTIN, OUTPUT); // set LED pin to OUTPUT
// call the toggle_led function every 1000 millis (1 second)
timer.every(1000, toggle_led);
// call the toggle_led function every 10000 millis (10 second)
timer.every(10000, toggle_led);
// call the toggle_gpio_26 function
timer.every(1000, toggle_gpio_26);
// Initialize the output variables as outputs
pinMode(output26, OUTPUT);
@ -222,19 +236,19 @@ void loop() {
float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
// 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);
} else {
output26State = "off";
}
// 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);
// } else {
// output26State = "off";
// }