const int totalSteps = 100;
const int microstepDelay = 1000;
int gpio_pins[] = {4, 5, 18, 19}; // Define the 4 GPIO pins to control the stepper motor
void setup() {
// Set GPIO pins as outputs
for (int i = 0; i < 4; i++) {
REG_WRITE(GPIO_ENABLE_W1TS_REG, (1 << gpio_pins[i])); // Enable the GPIO pin as output
}
}
void step_motor1() {
// Sequence for a 4-step motor control, assuming it's a 4-phase stepper
static int stepSequence[4][4] = {
{HIGH, LOW, LOW, LOW}, // Step 1
{HIGH, HIGH, LOW, LOW}, // Step 2
{LOW, HIGH, LOW, LOW}, // Step 3
{LOW, HIGH, HIGH, LOW} // Step 4
};
// Loop through each step in the sequence
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
// Set each pin according to the step sequence
if (stepSequence[i][j] == HIGH) {
REG_WRITE(GPIO_OUT_W1TS_REG, (1 << gpio_pins[j])); // Set the pin HIGH
} else {
REG_WRITE(GPIO_OUT_W1TC_REG, (1 << gpio_pins[j])); // Set the pin LOW
}
}
delay(microstepDelay); // Wait before next step
}
}
void loop() {
// Step the motor a certain number of steps
for (int i = 0; i < totalSteps; i++) {
step_motor1(); // Perform one step of the motor
}
}