-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loop config change and more examples
- Loading branch information
Showing
4 changed files
with
113 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <PciManager.h> | ||
#include <SoftTimer.h> | ||
#include <Debouncer.h> | ||
#include <DelayRun.h> | ||
|
||
#define INPUT_PIN 3 | ||
#define OUTPUT_PIN LED_BUILTIN | ||
|
||
// -- Define method signatures. | ||
void onPinChanged(); | ||
// -- Define method signatures. | ||
boolean turnOff(Task* task); | ||
|
||
Debouncer debouncer(INPUT_PIN, MODE_CLOSE_ON_PUSH, onPinChanged, NULL); | ||
// -- Runs after 2 seconds | ||
DelayRun offTask(2000, turnOff); | ||
|
||
void setup() { | ||
Serial.begin(9800); | ||
PciManager.registerListener(INPUT_PIN, &debouncer); | ||
pinMode(OUTPUT_PIN, OUTPUT); | ||
Serial.println("Ready."); | ||
} | ||
|
||
void onPinChanged() { | ||
Serial.println("Event occurred"); | ||
digitalWrite(OUTPUT_PIN, HIGH); | ||
offTask.startDelayed(); | ||
} | ||
|
||
boolean turnOff(Task* task) { | ||
Serial.println("Delay elapsed"); | ||
digitalWrite(OUTPUT_PIN, LOW); | ||
} |
74 changes: 74 additions & 0 deletions
74
examples/SoftTimer5DelayRunEsp8266WebServer/SoftTimer5DelayRunEsp8266WebServer.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <WiFiClient.h> | ||
#include <ESP8266WebServer.h> | ||
#include <ESP8266mDNS.h> | ||
#include <SoftTimer.h> | ||
#include <DelayRun.h> | ||
|
||
const char* ssid = "***"; | ||
const char* password = "***"; | ||
|
||
void myLoop(Task* me); | ||
boolean turnOff(Task* me); | ||
|
||
Task loopTask(0, myLoop); | ||
DelayRun turnOffTask(1000, turnOff); | ||
|
||
ESP8266WebServer server(80); | ||
|
||
const int led = 2; | ||
|
||
void handleRoot() { | ||
server.send(200, "text/html", | ||
"<html><body><button type=\"button\" onclick=\"var xhttp = new XMLHttpRequest();xhttp.open('GET', '/click', true);xhttp.send();\">Click Me!</button></body></html>" | ||
); | ||
} | ||
|
||
void setup(void){ | ||
pinMode(led, OUTPUT); | ||
digitalWrite(led, LOW); | ||
Serial.begin(115200); | ||
WiFi.mode(WIFI_STA); | ||
WiFi.begin(ssid, password); | ||
Serial.println("Connecting"); | ||
|
||
// Wait for connection | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
Serial.println(""); | ||
Serial.print("Connected to "); | ||
Serial.println(ssid); | ||
Serial.print("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
if (MDNS.begin("esp8266")) { | ||
Serial.println("MDNS responder started"); | ||
} | ||
|
||
server.on("/", handleRoot); | ||
|
||
server.on("/click", [](){ | ||
digitalWrite(led, LOW); | ||
Serial.println("Clicked"); | ||
turnOffTask.startDelayed(); | ||
server.send(200, "text/plain", "Okay"); | ||
}); | ||
|
||
server.begin(); | ||
Serial.println("HTTP server started"); | ||
SoftTimer.add(&loopTask); | ||
digitalWrite(led, HIGH); | ||
} | ||
|
||
void myLoop(Task* me) { | ||
// ESP.wdtFeed(); | ||
server.handleClient(); | ||
} | ||
|
||
boolean turnOff(Task* me) | ||
{ | ||
digitalWrite(led, HIGH); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters