Hello, I have a quick question about my code to control my stepper motor. Basically it's a bunch of "if" statements that read voltage and then decides how to turn the stepper motor. Everything is working real well, but I was wondering if there is a way for the stepper motor to skip having to take each step. What I mean is that when I want it to rotate 45 degrees, it hits each step at 1.8 degrees. Is there a way for it to move 45 degrees without hitting each step? I want to try and make the rotations smoother. Here is the code:
#include <StepperDriver.h>
int sensorPin = 0;
int dirPin = 8;
int stepPin = 9;
const int stepsPerRevolution = 200;
StepperDriver myStepper;
void setup()
{
myStepper.setStep(stepsPerRevolution, dirPin, stepPin);
myStepper.setSpeed(50);
myStepper.step(stepsPerRevolution*4);
Serial.begin(9600);
}
void loop()
{
int sensorValue = analogRead(sensorPin);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
if (voltage >= 4.5)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(stepsPerRevolution);
}
}
else if (voltage > 4.0 && voltage < 4.5)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(stepsPerRevolution/2);
}
}
else if (voltage > 3.5 && voltage <= 4.0)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(stepsPerRevolution/4);
}
}
else if (voltage > 3.0 && voltage <= 3.5)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(25);
}
}
else if (voltage > 2.6 && voltage <= 3.0)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(1);
}
}
else if (voltage > 2.0 && voltage <= 2.4)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(-1);
}
}
else if (voltage > 1.5 && voltage <= 2.0)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(-25);
}
}
else if (voltage > 1.0 && voltage <= 1.5)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(-stepsPerRevolution/4);
}
}
else if (voltage > 0.5 && voltage <= 1.0)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(-stepsPerRevolution/2);
}
}
else if (voltage >=0 && voltage <= 0.5)
{
if (myStepper.update() == 1)
{
delay(1000);
myStepper.step(-stepsPerRevolution);
}
}
}