#define stepPinX 1
#define dirPinX 2
#define stepPinY 3
#define dirPinY 4
const int stepsPerMillimeterX = 80; // Replace with your X axis motor's steps per mm
const int stepsPerMillimeterY = 80; // Replace with your Y axis motor's steps per mm
// Example positions in mm (X, Y)
int positions[][2] = {
{10, 5},
{20, 10},
{30, 15},
{-10, -5}, // Negative values for moving back to origin (0,0)
{0, 0} // Return to starting position
};
int numberOfPositions = sizeof(positions) / sizeof(positions[0]);
void setup() {
pinMode(stepPinX, OUTPUT);
pinMode(dirPinX, OUTPUT);
pinMode(stepPinY, OUTPUT);
pinMode(dirPinY, OUTPUT);
}
void loop() {
for (int i = 0; i < numberOfPositions; i++) {
moveStepperX(positions[i][0] * stepsPerMillimeterX);
moveStepperY(positions[i][1] * stepsPerMillimeterY);
delay(1000); // Wait for 1 second between moves
}
while (true) {
// Stop the loop after executing all moves
}
}
void moveStepperX(int steps) {
digitalWrite(dirPinX, steps >= 0 ? HIGH : LOW); // Set direction
for (int i = 0; i < abs(steps); i++) {
digitalWrite(stepPinX, HIGH);
delayMicroseconds(700);
digitalWrite(stepPinX, LOW);
delayMicroseconds(700);
}
}
void moveStepperY(int steps) {
digitalWrite(dirPinY, steps >= 0 ? HIGH : LOW); // Set direction
for (int i = 0; i < abs(steps); i++) {
digitalWrite(stepPinY, HIGH);
delayMicroseconds(700);
digitalWrite(stepPinY, LOW);
delayMicroseconds(700);
}
}