Hello,
I try to control a small robor with 2 motors with blynk. Its working basicly. But when I change direction, it always wants to continue the last direction. For example if I drive forward then press left, it still drives forward. Just when I press left once more (push mode button) it will drive to the left. I tried working with some delays no luck so far. Thank you
#define BLYNK_DEVICE_NAME "XXX"
#define BLYNK_AUTH_TOKEN "XXX"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
#define RightMotorSpeed D5 //14
#define RightMotorDir D6 //12
#define LeftMotorSpeed D7 //13
#define LeftMotorDir D8 //15
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXX";
char pass[] = "XXX";
// FORWARD
BLYNK_WRITE(V1) {
int button1 = param.asInt(); // read button
if (button1 == 1) {Serial.println("Moving forward"); digitalWrite(RightMotorDir,HIGH); digitalWrite(RightMotorSpeed,HIGH); digitalWrite(LeftMotorDir,HIGH); digitalWrite(LeftMotorSpeed,HIGH);
} else
{ Serial.println("Stop forward"); digitalWrite(RightMotorSpeed,LOW); digitalWrite(LeftMotorSpeed,LOW);
}
}
// BACKWARD
BLYNK_WRITE(V2) {
int button2 = param.asInt(); // read button
if (button2 == 2) {Serial.println("Moving backward"); digitalWrite(RightMotorDir,LOW); digitalWrite(RightMotorSpeed,HIGH); digitalWrite(LeftMotorDir,LOW); digitalWrite(LeftMotorSpeed,HIGH);
} else
{ Serial.println("Stop backward"); digitalWrite(RightMotorSpeed,LOW); digitalWrite(LeftMotorSpeed,LOW);
}
}
// LEFT
BLYNK_WRITE(V3) {
int button3 = param.asInt(); // read button
if (button3 == 3) {Serial.println("Moving left"); digitalWrite(LeftMotorSpeed,LOW); digitalWrite(LeftMotorDir,LOW); digitalWrite(RightMotorDir,HIGH); digitalWrite(RightMotorSpeed,HIGH);
} else
{ Serial.println("Stop left"); digitalWrite(RightMotorSpeed,LOW); digitalWrite(LeftMotorSpeed,LOW);
}
}
// RIGHT
BLYNK_WRITE(V4) {
int button4 = param.asInt(); // read button
if (button4 == 4) {Serial.println("Moving right"); digitalWrite(RightMotorSpeed,LOW); digitalWrite(RightMotorDir,LOW); digitalWrite(LeftMotorDir,HIGH); digitalWrite(LeftMotorSpeed,HIGH);
} else
{ Serial.println("Stop right"); digitalWrite(RightMotorSpeed,LOW); digitalWrite(LeftMotorSpeed,LOW);
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(RightMotorSpeed, OUTPUT);
pinMode(LeftMotorSpeed, OUTPUT);
pinMode(RightMotorDir, OUTPUT);
pinMode(LeftMotorDir, OUTPUT);
}
void loop()
{
Blynk.run();
}