Created
July 11, 2014 16:55
-
-
Save joelongstreet/c23d568fdb6a1019bd43 to your computer and use it in GitHub Desktop.
Short example on how to control a stepper motor
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
int M1dirpin = 4; | |
int M1steppin = 5; | |
void setup() | |
{ | |
pinMode(M1dirpin,OUTPUT); | |
pinMode(M1steppin,OUTPUT); | |
digitalWrite(M1dirpin,LOW); | |
} | |
void loop() | |
{ | |
delay(3000); | |
step(50, 1000); | |
} | |
// Where steps is total amount of steps taken | |
// and time is the total amount of time in microseconds | |
// the steps should take to complete | |
void step(int steps, int time){ | |
int delayTime = time/steps; | |
for(int i=0; i<steps; i++){ | |
digitalWrite(M1steppin, LOW); | |
delayMicroseconds(2); | |
digitalWrite(M1steppin, HIGH); | |
delay(delayTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment