Created
April 7, 2017 21:24
-
-
Save bogdanr/1bc97fd0326df7570b609393dae8477e to your computer and use it in GitHub Desktop.
WashingMachine
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
/* Comment this out to disable prints and save space */ | |
#define BLYNK_PRINT Serial | |
#include <ESP8266WiFi.h> | |
#include <BlynkSimpleEsp8266.h> | |
#include <SimpleTimer.h> | |
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal | |
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal | |
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic | |
// You should get Auth Token in the Blynk App. | |
// Go to the Project Settings (nut icon). | |
char auth[] = "87d1234567890123ab4b567a2d1e123a"; | |
// Your WiFi credentials. | |
// Set password to "" for open networks. | |
// We will need to replace this with the WiFiManager stuff | |
char ssid[] = "Radulescu"; | |
char pass[] = "obviouslyfake"; | |
// Select your pin with physical button | |
const int PinPW = 3; | |
const int PinLK = 5; | |
const int Pin40 = 4; | |
const int Pin60 = 2; | |
WidgetLED ledPW(V1); | |
WidgetLED ledLK(V2); | |
WidgetLED led40(V3); | |
WidgetLED led60(V4); | |
SimpleTimer timer; | |
// LED Widget represents the physical button state | |
boolean btnStatePW = false; | |
boolean btnStateLK = false; | |
boolean btnState40 = false; | |
boolean btnState60 = false; | |
void buttonLedWidget() | |
{ | |
// Read button | |
boolean isPressedPW = (digitalRead(PinPW) == LOW); | |
boolean isPressedLK = (digitalRead(PinLK) == LOW); | |
boolean isPressed40 = (digitalRead(Pin40) == LOW); | |
boolean isPressed60 = (digitalRead(Pin60) == LOW); | |
// If state has changed we change the LED... not the most elegant code but took one minute to write | |
if (isPressedPW != btnStatePW) { | |
if (isPressedPW) { | |
ledPW.on(); | |
} else { | |
ledPW.off(); | |
} | |
btnStatePW = isPressedPW; | |
} | |
if (isPressedLK != btnStateLK) { | |
if (isPressedLK) { | |
ledLK.on(); | |
} else { | |
ledLK.off(); | |
} | |
btnStateLK = isPressedLK; | |
} | |
if (isPressed40 != btnState40) { | |
if (isPressed40) { | |
led40.on(); | |
} else { | |
led40.off(); | |
} | |
btnState40 = isPressed40; | |
} | |
if (isPressed60 != btnState60) { | |
if (isPressed60) { | |
led60.on(); | |
} else { | |
led60.off(); | |
} | |
btnState60 = isPressed60; | |
} | |
} | |
void setup() | |
{ | |
// Debug console | |
Serial.begin(115200); | |
Blynk.begin(auth, ssid, pass); | |
// You can also specify server: | |
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442); | |
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442); | |
// Setup physical button pin (active low) | |
pinMode(PinPW, INPUT_PULLUP); | |
pinMode(Pin40, INPUT_PULLUP); | |
pinMode(Pin60, INPUT_PULLUP); | |
timer.setInterval(500L, buttonLedWidget); | |
} | |
void loop() | |
{ | |
Blynk.run(); | |
timer.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment