Skip to content

Instantly share code, notes, and snippets.

@nasustim
Last active February 18, 2018 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasustim/f69525107104b0e7c797478e29fd330b to your computer and use it in GitHub Desktop.
Save nasustim/f69525107104b0e7c797478e29fd330b to your computer and use it in GitHub Desktop.
arduino_stepping_motor
#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