Created
May 6, 2017 18:44
-
-
Save giantmolecules/d0f947a0c73ed015db4db88a6ee76394 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
// Whichever pin STEP is connected to | |
#define STEP_PIN 0 | |
// Whichever pin DIR is connected to | |
#define DIR_PIN 1 | |
void setup(){ | |
pinMode(STEP_PIN, OUTPUT); | |
pinMode(DIR_PIN, OUTPUT); | |
} | |
void loop(){ | |
// Move 1 REV FWD | |
move(200, 1); | |
// Wait a sec | |
delay(1000); | |
// Move 1 REV REV | |
move(200, 0); | |
// Wait a sec | |
delay(1000); | |
} | |
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