My project hardware at the moment includes a momentary push button, L298N 25w driver module, Arduino Uno R3 and a 12v 2amp stepper motor. More buttons to be added as the project develops.
Scope of the project is to use this system to power an optical linear screw rail to pre-programmed positions by number of steps. This will eventually include multiple buttons, each set to rotate the stepper motor in a chosen direction and number of steps.
At the moment I only have one button assigned to pin 2. When pressed the motor activates. When I release the button, the rotation stops. What I want to accomplish is to press it once and the motor rotate a certain number of steps, stop and hold until another button is pressed.
EXAMPLE: Press button 1 and the motor turns CW 1000 steps then stops. Press button 2 and the motor turns CCW 1000 steps and stops.
What needs to be changed on my sketch in order to make this happen? And.... annoying as it may be to so many more profficient Arduino programmers, I am definitely new at this and currently beyond my comfort level. I want to understand what I am telling it to do, but have had very little luck finding applicable instruction that fits my hardware needs. Tons of stuff out there for controlling the unipolar kit type steppers with buttons but those lines of code only cause my stepper to growl and jitter.
My code so far:
#include <Stepper.h>
int Distance = 0;
const int stepsPerRevolution = 512;
Stepper myStepper1(stepsPerRevolution, 8, 9, 10, 11);
int Switch = 2;
void setup() {
pinMode(Switch, INPUT_PULLUP);
myStepper1.setSpeed(100);
}
void loop() {
if(digitalRead(Switch) == LOW)
{myStepper1.step(1);
}
}
Suggestions? Hints to where I may find basic instruction to complete my project successfully? If I can get this thing to move a set distance with one button, return with another button, I can take it from there in baby steps. Thanks!