Created
July 3, 2021 19:01
-
-
Save a-h/db5d48a5cb1ea44a941b614b32d6386f to your computer and use it in GitHub Desktop.
Stepper motor test code (Arduino)
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
int ccw = LOW; | |
int step = D5; | |
int dir = D6; | |
int startDelay = 1000; | |
int speed = 10; | |
int targetDelay = 350; | |
void setup() | |
{ | |
pinMode(step, OUTPUT); | |
pinMode(dir, OUTPUT); | |
Serial.begin(115200); | |
} | |
void loop() | |
{ | |
int sleepMicroseconds = startDelay; | |
if (sleepMicroseconds > targetDelay) | |
{ | |
digitalWrite(dir, ccw); | |
sleepMicroseconds = sleepMicroseconds - speed; | |
if(sleepMicroseconds % 100 == 0) { | |
Serial.printf("%d\n", sleepMicroseconds); | |
} | |
} | |
digitalWrite(step, HIGH); | |
delayMicroseconds(sleepMicroseconds); | |
digitalWrite(step, LOW); | |
delayMicroseconds(sleepMicroseconds); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment