Hey I am working on a project in which I have to run several stepper motors using ESP32 Devkit module and Blynk via WIFI.
Every stepper motor is triggered by a virtual pin and I am using a while loop to run the motor as long as the button on the Blynk app is pressed and as soon as the button is released the motor comes to a stop.
The problem being faced is that once a button on the app is pressed and the control enters the while loop, it does not seem to break out of the loop when the button is released.
I have attached a code for one stepper motor below, which contains two BLYNK_WRITE(V?) functions to move the motor in either direction.
Let me know if there are any more questions.
#define BLYNK_PRINT Serial
#include <StepperDriver.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
char auth[] = "Your auth token";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Your SSID";
char pass[] = "Your Password";
int motor_steps = 200;
int step_divisition = 16;
int en1 = 34; int cw1 = 35; int clk1 = 32;
StepperDriver ss(motor_steps, step_divisition, en1, cw1, clk1); //CONVEYOR MOTOR
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(V3) //CONVEYOR FORWARD
{
int value3 = param.asInt();
while (value3 == 1)
{
ss.setSpeed(160);
ss.step(1);
}
}
BLYNK_WRITE(V4) //CONVEYOR REVERSE
{
int value4 = param.asInt();
while (value4 == 1)
{
ss.setSpeed(160);
ss.step(-1);
}
}
void loop()
{
Blynk.run();
}