Advertisement
Guest User

Untitled

a guest
Jul 28th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #define BLYNK_PRINT Serial
  2.  
  3.  
  4. #include <WiFi.h>
  5. #include <WiFiClient.h>
  6. #include <BlynkSimpleEsp32.h>
  7.  
  8. // You should get Auth Token in the Blynk App.
  9. // Go to the Project Settings (nut icon).
  10. char auth[] = "4b5tvAL_i-5FdWAal5vo69iPlnFMmfOf";
  11.  
  12. // Your WiFi credentials.
  13. // Set password to "" for open networks.
  14.  
  15. char ssid[] = "proeus";
  16. char pass[] = "7654321";
  17.  
  18.  
  19. // Set your LED and physical button pins here
  20. const int relePin1 = 14;
  21. const int relePin2 = 12;
  22.  
  23. const int btnPin1 = 4;
  24. const int btnPin2 = 5;
  25.  
  26. BlynkTimer timer;
  27. void checkPhysicalButton();
  28.  
  29. int releState1 = LOW;
  30. int releState2 = LOW;
  31. int btnState1 = LOW;
  32. int btnState2 = LOW;
  33.  
  34. // Every time we connect to the cloud...
  35. BLYNK_CONNECTED() {
  36. // Request the latest state from the server
  37. Blynk.syncVirtual(V2);
  38. Blynk.syncVirtual(V3);
  39.  
  40. // Alternatively, you could override server state using:
  41. //Blynk.virtualWrite(V2, releState1);
  42. }
  43.  
  44. // When App button is pushed - switch the state
  45. BLYNK_WRITE(V2) {
  46. // releState1 = param.asInt();
  47. subir ();
  48.  
  49. }
  50. BLYNK_WRITE(V3) {
  51. // releState2 = param.asInt();
  52. bajar();
  53.  
  54. }
  55.  
  56. void checkPhysicalButton()
  57. {
  58. if (digitalRead(btnPin1) == LOW) {
  59. // btnState1 is used to avoid sequential toggles
  60. if (btnState1 != LOW) {
  61.  
  62. // Toggle LED state
  63. //releState1 = !releState1;
  64. subir();
  65. // Update Button Widget
  66. Blynk.virtualWrite(V2, LOW);
  67. }
  68. btnState1 = LOW;
  69. } else {
  70. btnState1 = HIGH;
  71. }
  72.  
  73. if (digitalRead(btnPin2) == LOW) {
  74. // btnState2 is used to avoid sequential toggles
  75. if (btnState2 != LOW) {
  76.  
  77. // Toggle LED state
  78. //releState2 = !releState2;
  79. bajar();
  80. // Update Button Widget
  81. Blynk.virtualWrite(V3, LOW);
  82. }
  83. btnState2 = LOW;
  84. } else {
  85. btnState2 = HIGH;
  86. }
  87.  
  88. }
  89.  
  90. void setup()
  91. {
  92. // Debug console
  93. Serial.begin(9600);
  94.  
  95.  
  96. pinMode(relePin1, OUTPUT);
  97. pinMode(btnPin1, INPUT);
  98. digitalWrite(relePin1, LOW);
  99.  
  100. pinMode(relePin2, OUTPUT);
  101. pinMode(btnPin2, INPUT);
  102. digitalWrite(relePin2, LOW);
  103.  
  104. Blynk.begin(auth, ssid, pass);
  105.  
  106. // Setup a function to be called every 100 ms
  107. timer.setInterval(100L, checkPhysicalButton);
  108. }
  109.  
  110. void loop()
  111. {
  112. Blynk.run();
  113. timer.run();
  114. }
  115.  
  116. void subir()
  117. {
  118. digitalWrite(relePin2, HIGH);
  119. digitalWrite(relePin1, HIGH);
  120. delay (500);
  121. digitalWrite(relePin1, LOW);
  122. digitalWrite(relePin2, LOW);
  123. }
  124.  
  125. void bajar()
  126. {
  127. digitalWrite(relePin2, HIGH);
  128. delay (500);
  129. digitalWrite(relePin2, LOW);
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement