-
-
Save JeffersGlass/6c6ab91ab82add57f3eb3be09d5c3620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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