#include <AccelStepper.h>
 
class BiaxialStepperMotor {
private:
    AccelStepper stepperX, stepperY;
public:
    BiaxialStepperMotor(int pinX1, int pinX2, int pinY1, int pinY2) : stepperX(AccelStepper::FULL4WIRE, pinX1, pinX2), stepperY(AccelStepper::FULL4WIRE, pinY1, pinY2) {
        stepperX.setMaxSpeed(1000.0);
        stepperX.setAcceleration(500.0);
        stepperY.setMaxSpeed(1000.0);
        stepperY.setAcceleration(500.0);
    }
 
    void rotate(int stepsX, int stepsY) {
        stepperX.moveTo(stepsX);
        stepperY.moveTo(stepsY);
 
        while (stepperX.distanceToGo() != 0 || stepperY.distanceToGo() != 0) {
stepperX.run();
stepperY.run();
        }
    }
};
 
void setup() {
    Serial.begin(115200);
    int motorXPin1 = 2;
    int motorXPin2 = 3;
    int motorYPin1 = 4;
    int motorYPin2 = 5;
 
    BiaxialStepperMotor biaxialMotor(motorXPin1, motorXPin2, motorYPin1, motorYPin2);
}
 
void loop() {
    biaxialMotor.rotate(200, 200);
    delay(1000);  
}
has context menu