Skip to content

Instantly share code, notes, and snippets.

@giantmolecules
Last active May 6, 2017 18:39
Show Gist options
  • Save giantmolecules/867b12317d676a81586d0cd93ad18db4 to your computer and use it in GitHub Desktop.
Save giantmolecules/867b12317d676a81586d0cd93ad18db4 to your computer and use it in GitHub Desktop.
/*
Define STEP and DIRECTION PINS like:
#define STEP_PIN 1
#define DIR_PIN 2
at the start of the main program.
Put the function below at the end of the main program.
When you want to move, call move(steps, direction) from the main program
*/
void move(int steps, int direction){
digitalWrite(DIR_PIN, direction);
for(int i = 0; i < steps; i++){
digitalWrite(STEP_PIN, HIGH); //each time pin goes HIGH, moves one step
delayMicroseconds(2000); //delay determines speed of revolution (length of pause btwn steps)
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(2000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment