Skip to content

Instantly share code, notes, and snippets.

@a-h
Created July 3, 2021 19:01
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 a-h/db5d48a5cb1ea44a941b614b32d6386f to your computer and use it in GitHub Desktop.
Save a-h/db5d48a5cb1ea44a941b614b32d6386f to your computer and use it in GitHub Desktop.
Stepper motor test code (Arduino)
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