Engine control

#define BLYNK_TEMPLATE_ID "1"

#define BLYNK_TEMPLATE_NAME "1"

#define BLYNK_AUTH_TOKEN "1"

#define BLYNK_FIRMWARE_VERSION "0.1.0"

#define BLYNK_PRINT Serial

#include <BlynkSimpleEsp8266.h>

// Define motor pins

#define M1A D1

#define M1B D2

#define M2A D3

#define M2B D4

// Initialize the Blynk virtual pins

#define VIRTUAL_JOYSTICK_VERT_PIN V0

#define VIRTUAL_JOYSTICK_HOR_PIN V1

// Define variables to store joystick data

int joystick_vert;

int joystick_hor;

char auth[] = BLYNK_AUTH_TOKEN;

char ssid[] = "1";

char pass[] = "1";

void setup()

{

  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass, "blynk.cloud", 443);

 

  pinMode(M1A, OUTPUT);

  pinMode(M1B, OUTPUT);

  pinMode(M2A, OUTPUT);

  pinMode(M2B, OUTPUT);

}

void loop()

{

  Blynk.run();

  int joyY = map(Blynk.virtualRead(VIRTUAL_JOYSTICK_VERT_PIN), 0, 255, -100, 100);

  int joyX = map(Blynk.virtualRead(VIRTUAL_JOYSTICK_HOR_PIN), 0, 255, -100, 100);

  //wyliczenie prędkości silników na podstawie wartości joysticka

  int leftSpeed = joyY + joyX;

  int rightSpeed = joyY - joyX;

  //ograniczenie wartości prędkości do zakresu -100 do 100

  leftSpeed = max(min(leftSpeed, 100), -100);

  rightSpeed = max(min(rightSpeed, 100), -100);

  //ustawienie kierunku obrotu silników w trybie skręcania jak w czołgu

  if (leftSpeed > 0)

  {

    digitalWrite(M1A, HIGH);

    digitalWrite(M1B, LOW);

  }

  else

  {

    digitalWrite(M1A, LOW);

    digitalWrite(M1B, HIGH);

  }

  if (rightSpeed > 0)

  {

    digitalWrite(M2A, HIGH);

    digitalWrite(M2B, LOW);

  }

  else

  {

    digitalWrite(M2A, LOW);

    digitalWrite(M2B, HIGH);

  }

  //ustawienie wartości wypełnienia PWM na pinach sterujących silnikami

  analogWrite(abs(leftSpeed) * 2, abs(leftSpeed));

  analogWrite(abs(rightSpeed) * 2, abs(rightSpeed));

}

This error in the console

C:\Users\xxx\Desktop\silnik\silnik.ino: In function ‘void loop()’:
C:\Users\xxx\Desktop\silnik\silnik.ino:44:24: error: ‘class BlynkWifi’ has no member named ‘virtualRead’
44 | int joyY = map(Blynk.readVirtualPin(VIRTUAL_JOYSTICK_VERT_PIN), 0, 255, -100, 100);
| ^~~~~~~~~~~
C:\Users\xxx\Desktop\silnik\silnik.ino:45:24: error: ‘class BlynkWifi’ has no member named ‘virtualRead’
45 | int joyX = map(Blynk.readVirtualPin(VIRTUAL_JOYSTICK_HOR_PIN), 0, 255, -100, 100);
| ^~~~~~~~~~~

exit status 1

Compilation error: ‘class BlynkWifi’ has no member named ‘virtualRead’

Presumably this is a legacy sketch you found from somewhere and you are now trying to use it with Blynk IoT?

Blynk.virtualRead(vPin) isn’t supported in Blynk IoT, and even if it were, that command doesn’t belong in the void loop.

How good are your C++ coding skills?

Pete.

Using chatgpt.

Good luck with that!

Do you have zero C++ coding skills?

Pete.

Small, but I have been using Blynk for several years now.

In that case I find it strange that you don’t recognise the problems with the void loop in this ChatGPT generated sketch.

If you understand how you use virtual pins and BLYNK_WRITE(vPin) functions then you could possibly re-write this into something useable, but TBH I have no idea what it is that you are trying to achieve, what hardware you are using, so have no idea whether a re-written version of this sketch is going to work for you.

My advice would be to find a Blynk project that does what you want, or is at least close to that, then tweak it to work with Blynk IoT and do exactly what you want.

Pete.