// https://www.youtube.com/watch?v=c2jxorPyzvg
// https://forum.arduino.cc/t/arduino-uno-step-motors/1242758
// NO library but blocking loop
int stepPin[] = {3, 5, 7}; // motor step pins
int dirPin[] = {2, 4, 6}; // motor direction pins
bool CW = 1, CCW = 0; // clockwise, counterclockwise
int deg, dir = CW, mot; // degrees, direction, motor
#define stepsPerRevolution 200
void setup() {
deg = stepsPerRevolution / 4; // start at 90 degrees
for (int i = 0; i < 3; i++) { // three motors and drivers
pinMode(stepPin[i], OUTPUT); // configure step pins
pinMode(dirPin[i], OUTPUT); // configure direction pins
}
for (int mot = 0; mot < 3; mot++) {
runMotor(mot, dir, deg); // make 'mot' motor run in 'dir' direction for 'deg' degrees
delay(250); // pause between moving motors
}
}
void loop() {
dir = !dir; // change (negated) directions
deg = stepsPerRevolution / 2; // move to 180 degrees
for (int mot = 0; mot < 3; mot++) {
runMotor(mot, dir, deg); // make 'mot' motor run in 'dir' direction for 'deg' degrees
delay(250); // pause between moving motors
}
}
void runMotor(int motor, bool direction, int degrees) {
digitalWrite(dirPin[motor], direction);
for (int i = 0; i < deg; i++) {
// create one step pulse
digitalWrite(stepPin[motor], HIGH); // start of start pulse
delayMicroseconds(10);
digitalWrite(stepPin[motor], LOW); // end of start pulse
delayMicroseconds(1990);
}
}