Skip to content

Instantly share code, notes, and snippets.

@fxprime
Created January 7, 2023 09:00
Show Gist options
  • Save fxprime/050880d9a040ce5fbe0565ed3ae84e53 to your computer and use it in GitHub Desktop.
Save fxprime/050880d9a040ce5fbe0565ed3ae84e53 to your computer and use it in GitHub Desktop.
Control single stepper motor without library
const int dirPin = 8;
const int stepPin = 9;
const int enablePin = 7;
void setup() {
pinMode(enablePin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
digitalWrite(enablePin, LOW);
}
void loop() {
const int steps = 2000;
const int delayMicros = 500;
const int delayMillis = 1000;
digitalWrite(dirPin, HIGH);
for (int i = 0; i < steps; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(delayMicros);
digitalWrite(stepPin, LOW);
delayMicroseconds(delayMicros);
}
delay(delayMillis);
digitalWrite(dirPin, LOW);
for (int i = 0; i < steps; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(delayMicros);
digitalWrite(stepPin, LOW);
delayMicroseconds(delayMicros);
}
delay(delayMillis);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment