Created
March 9, 2019 03:20
-
-
Save gigafide/6b48bd73ff105041e9214e1dc01f81aa to your computer and use it in GitHub Desktop.
Arduino test code for the Sparkfun EasyDriver stepper motor controller
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
#define stp 2 | |
#define dir 3 | |
char user_input; | |
int x; | |
int y; | |
int state; | |
void setup() { | |
pinMode(stp, OUTPUT); | |
pinMode(dir, OUTPUT); | |
Serial.begin(9600); //Open Serial connection for debugging | |
Serial.println("Begin motor control"); | |
Serial.println(); | |
} | |
void loop() { | |
Serial.println("Moving forward at default step mode."); | |
digitalWrite(dir, LOW); //Pull direction pin low to move "forward" | |
for(x= 1; x<200; x++) //Loop the forward stepping enough times for motion to be visible | |
{ | |
digitalWrite(stp, HIGH); //Trigger one step forward | |
delay(1); | |
digitalWrite(stp, LOW); //Pull step pin low so it can be triggered again | |
delay(1); | |
} | |
delay(500); | |
Serial.println("Moving in reverse at default step mode."); | |
digitalWrite(dir, HIGH); //Pull direction pin high to move in "reverse" | |
for(y= 1; y<200; y++) //Loop the stepping enough times for motion to be visible | |
{ | |
digitalWrite(stp, HIGH); //Trigger one step | |
delay(1); | |
digitalWrite(stp, LOW); //Pull step pin low so it can be triggered again | |
delay(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment