Hello,
I just started learning programming
I want the stepper motor to rotate 400 steps 3 times at 30 second intervals. (It should stop if my potValue reaches 1023 while doing this) After delay(30000) I wrote "stepper.moveTo(400); " again but it didn't work. Is it possible to do that?
Thanks for your help.
#include <AccelStepper.h>
#define dirPin 8
#define stepPin 9
#define motorInterfaceType 1
const byte potPin = A0;
int potValue=0;
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup()
{
stepper.setMaxSpeed(1000); // Set the maximum speed in steps per second
stepper.setAcceleration(200);// Set the acceleration
Serial.begin(9600); //Set the serial communication speed
}
void loop()
{
potValue = analogRead(potPin);//at the beginning of each cyle, check the value of the potentiometer
if(potValue !=1023)
{
stepper.moveTo(400);// Set the target position
stepper.runToPosition();// Run to target position with set speed and acceleration/deceleration
Serial.print("Potentiometer at ");
Serial.println(potValue);
delay(30000);
}
else
{
stepper.stop();
}
}