Created
January 7, 2023 09:00
-
-
Save fxprime/050880d9a040ce5fbe0565ed3ae84e53 to your computer and use it in GitHub Desktop.
Control single stepper motor without library
This file contains 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
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