Last active
August 29, 2015 14:25
-
-
Save rfjakob/8f496ce2481ce71bf1a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // 500 is fastest, 1000 slower, ... | |
| #define ROT_SPEED 2000 | |
| #define PAUSE 2000 | |
| #define DIR_PIN 2 | |
| #define STEP_PIN 3 | |
| // necessary for driver standby | |
| #define SLP_PIN 4 | |
| // works also if not connected I guess | |
| #define MS1_PIN A4 | |
| #define MS2_PIN A5 | |
| // this is 2**(MS1 MS2) | |
| int micro_step = 8; | |
| void setup() | |
| { | |
| pinMode(DIR_PIN, OUTPUT); | |
| pinMode(STEP_PIN, OUTPUT); | |
| pinMode(SLP_PIN, OUTPUT); | |
| pinMode(MS1_PIN, OUTPUT); | |
| pinMode(MS2_PIN, OUTPUT); | |
| digitalWrite(MS1_PIN, HIGH); | |
| digitalWrite(MS2_PIN, HIGH); | |
| digitalWrite(DIR_PIN, HIGH); // Set the direction. | |
| } | |
| void move(int steps) | |
| { | |
| int i; | |
| // disable standby | |
| digitalWrite(SLP_PIN, HIGH); | |
| for (i = 0; i < steps; i++) | |
| { | |
| digitalWrite(STEP_PIN, LOW); // This LOW to HIGH change is what creates the | |
| delayMicroseconds(20); | |
| digitalWrite(STEP_PIN, HIGH); // "Rising Edge" so the easydriver knows to when to step. | |
| delayMicroseconds(ROT_SPEED); // This delay time is close to top speed for this | |
| // particular motor. Any faster the motor stalls. | |
| if(i < 20 || steps - i < 20) | |
| delayMicroseconds(2000); | |
| } | |
| // enable standby | |
| digitalWrite(SLP_PIN, LOW); | |
| } | |
| void loop() | |
| { | |
| // 60 degree rotation = 266.666 steps. | |
| // Approximate by alternating 266 and 267 | |
| move(267); | |
| delay(PAUSE); | |
| move(267); | |
| delay(PAUSE); | |
| move(266); | |
| delay(PAUSE); | |
| move(267); | |
| delay(PAUSE); | |
| move(266); | |
| delay(PAUSE); | |
| move(267); | |
| delay(PAUSE); | |
| // Sum of steps = 1600 = 360 degrees | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment