Advertisement
Guest User

Untitled

a guest
Dec 25th, 2016
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #define BLYNK_PRINT Serial
  2. #include <ESP8266_Lib.h>
  3. #include <BlynkSimpleShieldEsp8266.h>
  4. #include <SimpleTimer.h>
  5.  
  6. char auth[] = "";
  7.  
  8. char ssid[] = "Internety";
  9. char pass[] = "administrator";
  10.  
  11. const int lightPin = 43;
  12. const int blightPin = 37;
  13. const int lewePin = 40;
  14. const int prawePin = 41;
  15. const int testPin = 30;
  16. const int ruchPin = 38;
  17. WidgetLED led4(V4);
  18. WidgetLED led5(V5);
  19. WidgetLED led6(V6);
  20. WidgetLED led7(V7);
  21. SimpleTimer timer;
  22. void checkPhysicalButton();
  23.  
  24. int lightState = LOW;
  25. int blightState = HIGH;
  26. #define EspSerial Serial1
  27.  
  28. #define ESP8266_BAUD 9600
  29.  
  30. ESP8266 wifi(&EspSerial);
  31.  
  32. void setup()
  33. {
  34. Serial.begin(9600);
  35. delay(10);
  36. EspSerial.begin(ESP8266_BAUD);
  37. delay(10);
  38. pinMode(lightPin, OUTPUT);
  39. pinMode(blightPin, INPUT_PULLUP);
  40. digitalWrite(lightPin, lightState);
  41. pinMode(lewePin, INPUT_PULLUP);
  42. pinMode(prawePin, INPUT_PULLUP);
  43. pinMode(testPin, INPUT_PULLUP);
  44. pinMode(ruchPin, INPUT_PULLUP);
  45. timer.setInterval(100L, checkPhysicalButton);
  46. timer.setInterval(500L, buttonLedWidget4);
  47. timer.setInterval(500L, buttonLedWidget5);
  48. timer.setInterval(500L, buttonLedWidget6);
  49. timer.setInterval(500L, buttonLedWidget7);
  50. Blynk.begin(auth, wifi, ssid, pass);
  51. }
  52. BLYNK_CONNECTED() {
  53. Blynk.syncVirtual(V3);
  54. }
  55. BLYNK_WRITE(V3) {
  56. lightState = param.asInt();
  57. digitalWrite(lightPin, lightState);
  58. }
  59. void checkPhysicalButton()
  60. {
  61. if (digitalRead(blightPin) == LOW) {
  62. // btnState is used to avoid sequential toggles
  63. if (blightState != LOW) {
  64.  
  65. // Toggle LED state
  66. lightState = !lightState;
  67. digitalWrite(lightPin, lightState);
  68.  
  69. // Update Button Widget
  70. Blynk.virtualWrite(V3, lightState);
  71. }
  72. blightState = LOW;
  73. } else {
  74. blightState = HIGH;
  75. }
  76. }
  77. boolean leweState = false;
  78. void buttonLedWidget4()
  79. {
  80. boolean isPressed = (digitalRead(lewePin) == LOW);
  81. if (isPressed != leweState) {
  82. if (isPressed) {
  83. led4.on();
  84. } else {
  85. led4.off();
  86. }
  87. leweState = isPressed;
  88. }
  89. }
  90. boolean praweState = false;
  91. void buttonLedWidget5()
  92. {
  93. boolean isPressed = (digitalRead(prawePin) == LOW);
  94. if (isPressed != praweState) {
  95. if (isPressed) {
  96. led5.on();
  97. } else {
  98. led5.off();
  99. }
  100. praweState = isPressed;
  101. }
  102. }
  103. boolean testState = false;
  104. void buttonLedWidget6()
  105. {
  106. boolean isPressed = (digitalRead(testPin) == LOW);
  107. if (isPressed != testState) {
  108. if (isPressed) {
  109. led6.off();
  110. } else {
  111. led6.on();
  112. }
  113. testState = isPressed;
  114. }
  115. }
  116. boolean ruchState = false;
  117. void buttonLedWidget7()
  118. {
  119. boolean isPressed = (digitalRead(ruchPin) == LOW);
  120. if (isPressed != ruchState) {
  121. if (isPressed) {
  122. led7.off();
  123. } else {
  124. led7.on();
  125. }
  126. ruchState = isPressed;
  127. }
  128. }
  129. void loop()
  130. {
  131. Blynk.run();
  132. timer.run();
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement