Created
December 15, 2013 00:21
-
-
Save gnidan/7966911 to your computer and use it in GitHub Desktop.
stepper motor code with switch controlled direction
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> | |
// change this to the number of steps on your motor | |
#define STEPS 64 | |
#define SWITCH_PIN A0 | |
// create an instance of the stepper class, specifying | |
// the number of steps of the motor and the pins it's | |
// attached to | |
Stepper stepper(STEPS, 8, 10, 9, 11); | |
void setup() | |
{ | |
pinMode(SWITCH_PIN, INPUT); | |
Serial.begin(9600); | |
stepper.setSpeed(230); | |
} | |
void loop() | |
{ | |
int stepsToTake = 64; | |
bool switchValue = digitalRead(SWITCH_PIN); | |
Serial.println(switchValue); | |
if (switchValue) { | |
stepsToTake *= -1; | |
} | |
stepper.step(stepsToTake); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment