const byte STEPPER_MOTOR_1_PIN = 32;
const byte STEPPER_MOTOR_2_PIN = 33;
const byte STEPPER_MOTOR_3_PIN = 34;
const byte STEPPER_MOTOR_4_PIN = 35;
const byte STEPPER_PINS[] = { STEPPER_MOTOR_1_PIN, STEPPER_MOTOR_2_PIN, STEPPER_MOTOR_3_PIN, STEPPER_MOTOR_4_PIN };
const byte STEPPER_PATTERNS[4][4] = { { HIGH, LOW, LOW, LOW }, { LOW, HIGH, LOW, LOW }, { LOW, LOW, HIGH, LOW }, { LOW, LOW, LOW, HIGH } };
void stepper(const boolean reverse = false) {
static byte step_index = 0;
for (byte i = 0; i < 4; i++)
digitalWrite(STEPPER_PINS[i], STEPPER_PATTERNS[reverse ? (3 - step_index) : step_index][i]);
step_index = (step_index + 1) % 4;
}
This is the code I created to operate a single-phase excitation stepper motor.
Without an argument it moves one step clockwise, and if you pass true as an argument it moves one step counterclockwise.
As you can see from STEPPER_PATTERNS, in this case there is only one pin that goes HIGH.
Please add this pattern.
This is the code I created to operate a single-phase excitation stepper motor.
Without an argument it moves one step clockwise, and if you pass true as an argument it moves one step counterclockwise.
As you can see from
STEPPER_PATTERNS, in this case there is only one pin that goesHIGH.Please add this pattern.