im making a school project with 2 power window, mdd10a dual driver and nodemcu. However. both motor wont go backwards, it only goes forward right and left in my blynk. Help please? heres my code:
#include <Blynk.h>
#include <Servo.h>
#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[] = "a57b0e58d63941eaa9d63c6fa200b99c";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "KKK";
char pass[] = "kenken999";
#define m11 D0 //pwm1
#define m12 D3 //dir1
#define m21 D7 //pwm2
#define m22 D6 //dir2
Servo servo1;
void forward()
{
analogWrite(m11, 300);
analogWrite(m21, 300);
digitalWrite(m12,LOW);
digitalWrite(m22,LOW);
}
void backward()
{
digitalWrite(m11,LOW);
analogWrite(m12,300);
digitalWrite(m21,LOW);
analogWrite(m22,300);
}
void right()
{
analogWrite(m11, 300);
digitalWrite(m12,LOW);
digitalWrite(m21,LOW);
digitalWrite(m22,LOW);
}
void left()
{
digitalWrite(m11, LOW);
digitalWrite(m12,LOW);
analogWrite(m21, 300);
digitalWrite(m22,LOW);
}
void Stop()
{
digitalWrite(m11, LOW);
digitalWrite(m12,LOW);
digitalWrite(m21,LOW);
digitalWrite(m22,LOW);
}
void setup()
{
servo1.attach(15);
// Debug console
Serial.begin(115200);
// Set console baud rate
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
// 9600 is recommended for Software Serial
delay(10);
Blynk.begin(auth, ssid, pass);
pinMode(m11, OUTPUT);
pinMode(m12, OUTPUT);
pinMode(m21, OUTPUT);
pinMode(m22, OUTPUT);
}
BLYNK_WRITE(V1)
{
int x = param[0].asInt();
int y = param[1].asInt();
// Do something with x and y
/* Serial.print("X = ");
Serial.print(x);
Serial.print("; Y = ");
Serial.println(y);*/
if(y>220)
forward();
else if(y<35)
backward();
else if(x>220)
right();
else if(x<35)
left();
else
Stop();
}
BLYNK_WRITE(V0)//
{
int motorSpeed = param.asInt();
analogWrite(m21,map(motorSpeed,0,100,0,255));
analogWrite(m11,map(motorSpeed,0,100,0,255));
}
void loop()
{
Blynk.run();
}