Created
May 15, 2020 02:10
-
-
Save ameyer/7fed2074799dc0f30489f28989e8f020 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
#define DIR_PIN 2 | |
#define STEP_PIN 3 | |
void setup() { | |
pinMode(DIR_PIN, OUTPUT); | |
pinMode(STEP_PIN, OUTPUT); | |
} | |
void loop(){ | |
rotate(1600, .25); | |
delay(1000); | |
} | |
void rotate(int steps, float speed){ | |
int dir = (steps > 0)? HIGH:LOW; | |
steps = abs(steps); | |
digitalWrite(DIR_PIN,dir); | |
float usDelay = (1/speed) * 70; | |
for(int i=0; i < steps; i++){ | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment