Im having issues with my code, I’m trying to get my stepper motor to turn forwards and backwards (Left/Right) Depending on the V1 & V2 buttons being pushed. However the code doesn’t seem to be activating
Here is my code
#include <Stepper.h>;
#include <AccelStepper.h>
#include <SPI.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
char auth[] = "62b6ba779d0e47d3850d031059bea256";
#define ENABLE 8
AccelStepper stepper1(2, 5); // pin 3 = step, pin 6 = direction
void setup() {
pinMode(ENABLE, OUTPUT);
SwSerial.begin(9600);
Serial.begin(9600);
delay(10);
Blynk.begin(Serial, auth);
delay(10);
while (Blynk.connect() == false) {
}
}
BLYNK_WRITE(V2) // Button Widget writes to Virtual Pin V5
{
int rightBtn = param.asInt();
if(rightBtn == 1) { // if Button sends 1
right(); // start the function
}
}
void right(){
digitalWrite(ENABLE, LOW);
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(1000);
}
BLYNK_WRITE(V1) // Button Widget writes to Virtual Pin V5
{
int leftBtn = param.asInt();
if(leftBtn == 1) { // if Button sends 1
left(); // start the function
}
}
void left(){
digitalWrite(ENABLE, LOW);
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(500.0);
stepper1.moveTo(-1000);
}
void loop() {
stepper1.run();
}