Here is what I have so far to control the NodeMCU using the ESP8266 Standalone example and your code as a template. I have added steering that is working for now but just for forward and not reverse. I will add reverse steering tomorrow and next week, I will work on tuning the performance. By the way, the single joystick is no longer available so I used the 2 axis joystick in merge mode and adjusted the code accordingly.
//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int motorA ;
int motorB ;
int X=0;
int Y=0;
int factor=0;
int maximo=0;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "b41ff7f1659b4badb694be4c59601c2c";
void setup()
{
// Set console baud rate
Serial.begin(9600);
Blynk.begin(auth,"100Grand","Mob4life");
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);
pinMode(0,OUTPUT);
pinMode(2,OUTPUT);
}
BLYNK_WRITE(V1)
{
int X1 = param[0].asInt();
X=X1;
int Y1 = param[1].asInt();
Y=Y1;
}
BLYNK_WRITE(V0)// slider de 100 a 255!!!!
{
int vel = param.asInt();
maximo=vel;
}
void loop()
{
if(X == 128 && Y == 128) // Stop
{
motorA = 0;
motorB = 0;
analogWrite(5, motorA);
analogWrite(4, motorA);
analogWrite(0, motorB);
analogWrite(2, motorB);
}
if(X > 123 && X < 132 && Y >= 129) //Forward
{
motorA = Y;
motorB = Y;
motorA = map(motorA, 129,255 , 450,maximo);
analogWrite(5, motorA);
digitalWrite(0,LOW);
motorB = map(motorB, 129,255 , 450,maximo);
analogWrite(4, motorB);
digitalWrite(2,HIGH);
}
else if(X > 123 && X < 132 && Y <= 127) //Reverse
{
motorA = Y;
motorB = Y;
motorA = map(motorA, 127,0 , 450,maximo);
analogWrite(5, motorA);
digitalWrite(0,HIGH);
motorB = map(motorB, 127,0 , 450,maximo);//something is wrong with HIGH signal
analogWrite(4, motorB);
digitalWrite(2,LOW);
}
else if(Y > 123 && Y < 132 && X <= 127) //Left
{
motorA = X;
motorB = X;
motorA = map(motorA, 127,0 , 450,maximo);
analogWrite(5, motorA);
digitalWrite(0,HIGH);
motorB = map(motorB, 127,0 , 450,maximo);//something is wrong with HIGH signal
analogWrite(4, motorB);
digitalWrite(2,HIGH);
}
else if(Y > 123 && Y < 132 && X >= 127) //Right
{
motorA = X;
motorB = X;
motorA = map(motorA, 129,255 , 450,maximo);
analogWrite(5, motorA);
digitalWrite(0,LOW);
motorB = map(motorB, 129,255 , 450,maximo);//something is wrong with HIGH signal
analogWrite(4, motorB);
digitalWrite(2,LOW);
}
if(X >= 129 && Y >= 129) //Forward Right Steering
{
motorA = Y;
motorB = Y;
factor = X;
factor= map(factor,129,255, 0,200);
motorA = map(motorA, 129,255 , 450,maximo);
analogWrite(5, motorA);
digitalWrite(0,LOW);
motorB = map(motorB, 129,255 , 450,maximo);
analogWrite(4, (motorB-factor));
digitalWrite(2,HIGH);
}
else if(X <= 127 && Y >=129) //Forward Left Steering
{
motorA = Y;
motorB = Y;
factor = X;
factor= map(factor,127,0, 0,150);
motorA = map(motorA, 129,255 , 450,maximo);
analogWrite(5, (motorA-factor));
digitalWrite(0,LOW);
motorB = map(motorB, 129,255 , 450,maximo);
analogWrite(4, motorB);
digitalWrite(2,HIGH);
}
Blynk.run();
}