I would like to know how I can set the stepper in idle state, after the assigned task. I control it with a touch interrupter, which with a touch turn right and with another turn left. Thanks
#include <AccelStepper.h>
AccelStepper motor1(1, 50, 48);
int pos1 = 2000;
int pos0 = -2000;
int contador1 = 0;
void setup() {
Serial.begin(9600);
pinMode (51, INPUT); //touch1
motor1.setEnablePin(52);
//motor1.setPinsInverted(false, false, true);
motor1.setMaxSpeed(1000);
motor1.setAcceleration(300);
}
void loop() {
to1();
mot1();
}
void to1() {
int tou1 = digitalRead(51);
if (tou1 == 0) {
contador1++;
if (contador1 == 2) {
contador1 = 0;
}
Serial.println(contador1);
while (!digitalRead(51));
motor1.enableOutputs();
}
}
void mot1() {
if (contador1 == 1) {
if (motor1.distanceToGo() == 0)
{
motor1.moveTo(pos1);
}
motor1.run();
} else if (contador1 == 0) {
if (motor1.distanceToGo() == 0)
{
motor1.moveTo(pos0);
}
motor1.run();
}
}