Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial
- #include <ESP8266_Lib.h>
- #include <BlynkSimpleShieldEsp8266.h>
- #include <SimpleTimer.h>
- char auth[] = "";
- char ssid[] = "Internety";
- char pass[] = "administrator";
- const int lightPin = 43;
- const int blightPin = 37;
- const int lewePin = 40;
- const int prawePin = 41;
- const int testPin = 30;
- const int ruchPin = 38;
- WidgetLED led4(V4);
- WidgetLED led5(V5);
- WidgetLED led6(V6);
- WidgetLED led7(V7);
- SimpleTimer timer;
- void checkPhysicalButton();
- int lightState = LOW;
- int blightState = HIGH;
- #define EspSerial Serial1
- #define ESP8266_BAUD 9600
- ESP8266 wifi(&EspSerial);
- void setup()
- {
- Serial.begin(9600);
- delay(10);
- EspSerial.begin(ESP8266_BAUD);
- delay(10);
- pinMode(lightPin, OUTPUT);
- pinMode(blightPin, INPUT_PULLUP);
- digitalWrite(lightPin, lightState);
- pinMode(lewePin, INPUT_PULLUP);
- pinMode(prawePin, INPUT_PULLUP);
- pinMode(testPin, INPUT_PULLUP);
- pinMode(ruchPin, INPUT_PULLUP);
- timer.setInterval(100L, checkPhysicalButton);
- timer.setInterval(500L, buttonLedWidget4);
- timer.setInterval(500L, buttonLedWidget5);
- timer.setInterval(500L, buttonLedWidget6);
- timer.setInterval(500L, buttonLedWidget7);
- Blynk.begin(auth, wifi, ssid, pass);
- }
- BLYNK_CONNECTED() {
- Blynk.syncVirtual(V3);
- }
- BLYNK_WRITE(V3) {
- lightState = param.asInt();
- digitalWrite(lightPin, lightState);
- }
- void checkPhysicalButton()
- {
- if (digitalRead(blightPin) == LOW) {
- // btnState is used to avoid sequential toggles
- if (blightState != LOW) {
- // Toggle LED state
- lightState = !lightState;
- digitalWrite(lightPin, lightState);
- // Update Button Widget
- Blynk.virtualWrite(V3, lightState);
- }
- blightState = LOW;
- } else {
- blightState = HIGH;
- }
- }
- boolean leweState = false;
- void buttonLedWidget4()
- {
- boolean isPressed = (digitalRead(lewePin) == LOW);
- if (isPressed != leweState) {
- if (isPressed) {
- led4.on();
- } else {
- led4.off();
- }
- leweState = isPressed;
- }
- }
- boolean praweState = false;
- void buttonLedWidget5()
- {
- boolean isPressed = (digitalRead(prawePin) == LOW);
- if (isPressed != praweState) {
- if (isPressed) {
- led5.on();
- } else {
- led5.off();
- }
- praweState = isPressed;
- }
- }
- boolean testState = false;
- void buttonLedWidget6()
- {
- boolean isPressed = (digitalRead(testPin) == LOW);
- if (isPressed != testState) {
- if (isPressed) {
- led6.off();
- } else {
- led6.on();
- }
- testState = isPressed;
- }
- }
- boolean ruchState = false;
- void buttonLedWidget7()
- {
- boolean isPressed = (digitalRead(ruchPin) == LOW);
- if (isPressed != ruchState) {
- if (isPressed) {
- led7.off();
- } else {
- led7.on();
- }
- ruchState = isPressed;
- }
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement