Hi All,
I have made an attempt to write my own program, however i'm still struggling to get it to do what i want it to do, some help would be greatful.
When I the button it ramps up but if i release the button it will stop but when i press it again it again it continues to ramp from where it was. I need it to start the ramp again from zero, every time the button is pressed and either stop sharply or ramp down when the button is released.
Here is my code;
#include <AccelStepper.h>
#include <MultiStepper.h>
AccelStepper motor(1, 7, 8);
const int buttonPin = 3; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
motor.setMaxSpeed(4800);
motor.setAcceleration(800);
motor.setMinPulseWidth(100);
motor.setCurrentPosition(0);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is low:
if (buttonState == LOW) {
motor.moveTo(24000);
motor.run();
} else {
motor.move(0);
motor.setSpeed(0.0f);
}
}
Kind Regards, Luke