Skip to content

Instantly share code, notes, and snippets.

@nrdobie
Forked from anonymous/gist:8245756
Last active January 2, 2016 04:19
Show Gist options
  • Save nrdobie/8249266 to your computer and use it in GitHub Desktop.
Save nrdobie/8249266 to your computer and use it in GitHub Desktop.
#include <AccelStepper.h>
//AccelStepper stepper
#define BUTTON_PIN 8
#define MOTOR_DIRECTION_PIN 2
#define MOTOR_STEPPER_PIN 3
#define MOTOR_ACCELERATION 80000
#define SENSOR_1 A0
#define SENSOR_2 A5
//set up the accelStepper intance
//the "1" tells it we are using a driver
AccelStepper stepper(1, MOTOR_STEPPER_PIN, MOTOR_DIRECTION_PIN);
void setup ()
{
Serial.begin(9600);
updateSpeed(0);
stepper.setAcceleration(MOTOR_ACCELERATION);
pinMode(BUTTON_PIN, INPUT);
}
void loop()
{
if (Serial.available() > 0 ) {
int temp = Serial.parseInt();
Serial.flush();
if (temp >= -9600 && temp <= 9600) {
updateSpeed(temp);
Serial.print("Speed set to: ");
Serial.println(temp);
} else if (temp == 9601) {
Serial.println(analogRead(SENSOR_1));
} else if (temp == 9602) {
Serial.println(analogRead(SENSOR_2))
} else if (temp == 9603) {
Serial.print("Current step position: ");
Serial.println(stepper.currentPosition());
} else {
Serial.println("Invalid Input");
}
}
if (digitalRead(BUTTON_PIN) == HIGH) {
Serial.println(millis());
}
stepper.run();
}
void updateSpeed(int speed)
{
stepper.setMaxSpeed(speed);
stepper.setSpeed(speed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment