Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass

JeffersGlass/stepper_goStop.ino Secret

Last active Apr 5, 2020
Embed
What would you like to do?
#include <Stepper.h>
const int stepsPerRevolution = 400; // change this to fit the number of steps per revolution
// for your motor
const int BUTTON_CLOCKWISE = 7;
const int BUTTON_COUNTERCLOCKWISE = 6;
const int SINGLE_STEP = 1;
int stepValue = 0;
long lastButtonTime;
const int TIMEOUT = 500;
const int PINS[4] = {8, 9, 10, 11};
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, PINS[0], PINS[1], PINS[2], PINS[3]);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
pinMode(BUTTON_CLOCKWISE, INPUT_PULLUP);
pinMode(BUTTON_COUNTERCLOCKWISE, INPUT_PULLUP);
lastButtonTime = 0;
}
void loop() {
if (millis() > lastButtonTime + TIMEOUT){
if (digitalRead(BUTTON_CLOCKWISE) == LOW and digitalRead(BUTTON_COUNTERCLOCKWISE) == LOW){
stepValue = 0;
lastButtonTime = millis();
}
else if (digitalRead(BUTTON_CLOCKWISE) == LOW){
stepValue = 1;
lastButtonTime = millis();
}
else if (digitalRead(BUTTON_COUNTERCLOCKWISE) == LOW){
stepValue = -1;
lastButtonTime = millis();
}
}
myStepper.step(SINGLE_STEP * stepValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.