Last active
February 18, 2018 04:28
-
-
Save nasustim/f69525107104b0e7c797478e29fd330b to your computer and use it in GitHub Desktop.
arduino_stepping_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
#define DIR_PIN 2 | |
#define STEP_PIN 3 | |
void rotateDeg(float deg, float speed, int dec){ | |
//deg -= dec; | |
//deg = -dec; | |
//Serial.println(deg); | |
deg *= 0.6666666; | |
int dir = (deg > 0) ? HIGH : LOW; | |
digitalWrite(DIR_PIN, dir); | |
int steps = abs(deg) * (1 / 0.225); | |
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