#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
BlynkTimer timer;
char ssid[] = "xxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxx";
int pul1 = D6; //derecha
int pul2 = D7;
int pul3 = D4; //izquierdita
int pul4 = D5;
int LeftPin = D8; //motor
int RightPin = D9; //motor
int a;
int b;
int MOTOR;
int c;
int d;
int sw1;
int sw2;
int PULS1;
int PULS2;
void setup() {
//pinMode(pul1, INPUT);
pinMode(pul2, INPUT);
//pinMode(pul3, INPUT);
pinMode(pul4, INPUT);
pinMode(LeftPin, OUTPUT);
pinMode(RightPin, OUTPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(20L, motorDC);
Serial.begin(9600);
MOTOR=0;
sw1=0;
sw2=0;
a=1;
c=1;
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_WRITE(V7)
{
motorDC();
a = param.asInt();
motorDC();
}
BLYNK_WRITE(V8)
{
motorDC();
c = param.asInt();
motorDC();
}
void motorDC() {
PULS1 = digitalRead(pul1);
b = digitalRead(pul2);
if(a == LOW && sw1 == 0)
{
//digitalWrite(b, LOW);
sw1=1;
if(MOTOR == 0 && b==HIGH)
{
digitalWrite(LeftPin, LOW);
digitalWrite(RightPin, HIGH);
MOTOR=1;
Serial.println("on");
}
else
{
digitalWrite(RightPin, LOW);
digitalWrite(LeftPin, LOW);
MOTOR=0;
}
}
else if(a == HIGH && sw1 == 1)
{
sw1 = 0;
}
if(MOTOR == 1 && b==LOW)
{
digitalWrite(RightPin, LOW);
MOTOR=0;
}
PULS2 = digitalRead(pul3);
d = digitalRead(pul4);
if(c == LOW && sw2 == 0)
{
sw2=1;
if(MOTOR == 0 && d==HIGH)
{
digitalWrite(LeftPin, HIGH);
digitalWrite(RightPin, LOW);
MOTOR=1;
Serial.println("on");
}
else
{
digitalWrite(RightPin, LOW);
digitalWrite(LeftPin, LOW);
MOTOR=0;
}
}
else if(c == HIGH && sw2 == 1)
{
sw2 = 0;
}
if(MOTOR == 1 && d==LOW)
{
digitalWrite(LeftPin, LOW);
MOTOR=0;
}
}
Quiero poder sincronizar los pulsadores PULS1 con V7 de Blynk, y PULS2 con V8 de Blynk.
Estuve viendo el ejemplo de sync physical button pero no logro entenderlo.