Skip to content

Instantly share code, notes, and snippets.

@gnidan
Created December 15, 2013 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnidan/7966911 to your computer and use it in GitHub Desktop.
Save gnidan/7966911 to your computer and use it in GitHub Desktop.
stepper motor code with switch controlled direction
#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