#include <AccelStepper.h>
// Define some steppers and the pins the will use
AccelStepper Base(AccelStepper::DRIVER, 9, 8);
int angle;
bool BaseHomePos = false;
void setup() {
Serial.begin(115200);
pinMode(12, INPUT_PULLUP);
Base.setMaxSpeed(1600.0);
Base.setAcceleration(1600.0);
}
void loop() {
angle = 180;
if (BaseHomePos == false) {
if (digitalRead(12) == LOW) {
//Stops the motor whenever it is pressed
Base.stop();
Serial.println(Base.currentPosition());
//sets the stop position as home position
Base.setCurrentPosition(0);
Serial.println(Base.currentPosition());
//Gives information to the system that the robotic arm is home positioned
BaseHomePos = true;
delay(250);
}
else if (digitalRead(12) == HIGH) {
Base.run();
Base.moveTo(-10000);
}
}
else if (BaseHomePos == true) {
Base.run();
Base.moveTo(map(angle, 0, 180, 0, 1600));
}
//Serial.println(computeNewSpeed());
}