Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <BlynkSimpleEsp32.h>
- // You should get Auth Token in the Blynk App.
- // Go to the Project Settings (nut icon).
- char auth[] = "4b5tvAL_i-5FdWAal5vo69iPlnFMmfOf";
- // Your WiFi credentials.
- // Set password to "" for open networks.
- char ssid[] = "proeus";
- char pass[] = "7654321";
- // Set your LED and physical button pins here
- const int relePin1 = 14;
- const int relePin2 = 12;
- const int btnPin1 = 4;
- const int btnPin2 = 5;
- BlynkTimer timer;
- void checkPhysicalButton();
- int releState1 = LOW;
- int releState2 = LOW;
- int btnState1 = LOW;
- int btnState2 = LOW;
- // Every time we connect to the cloud...
- BLYNK_CONNECTED() {
- // Request the latest state from the server
- Blynk.syncVirtual(V2);
- Blynk.syncVirtual(V3);
- // Alternatively, you could override server state using:
- //Blynk.virtualWrite(V2, releState1);
- }
- // When App button is pushed - switch the state
- BLYNK_WRITE(V2) {
- // releState1 = param.asInt();
- subir ();
- }
- BLYNK_WRITE(V3) {
- // releState2 = param.asInt();
- bajar();
- }
- void checkPhysicalButton()
- {
- if (digitalRead(btnPin1) == LOW) {
- // btnState1 is used to avoid sequential toggles
- if (btnState1 != LOW) {
- // Toggle LED state
- //releState1 = !releState1;
- subir();
- // Update Button Widget
- Blynk.virtualWrite(V2, LOW);
- }
- btnState1 = LOW;
- } else {
- btnState1 = HIGH;
- }
- if (digitalRead(btnPin2) == LOW) {
- // btnState2 is used to avoid sequential toggles
- if (btnState2 != LOW) {
- // Toggle LED state
- //releState2 = !releState2;
- bajar();
- // Update Button Widget
- Blynk.virtualWrite(V3, LOW);
- }
- btnState2 = LOW;
- } else {
- btnState2 = HIGH;
- }
- }
- void setup()
- {
- // Debug console
- Serial.begin(9600);
- pinMode(relePin1, OUTPUT);
- pinMode(btnPin1, INPUT);
- digitalWrite(relePin1, LOW);
- pinMode(relePin2, OUTPUT);
- pinMode(btnPin2, INPUT);
- digitalWrite(relePin2, LOW);
- Blynk.begin(auth, ssid, pass);
- // Setup a function to be called every 100 ms
- timer.setInterval(100L, checkPhysicalButton);
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
- void subir()
- {
- digitalWrite(relePin2, HIGH);
- digitalWrite(relePin1, HIGH);
- delay (500);
- digitalWrite(relePin1, LOW);
- digitalWrite(relePin2, LOW);
- }
- void bajar()
- {
- digitalWrite(relePin2, HIGH);
- delay (500);
- digitalWrite(relePin2, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement