PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 line
1.2KB

  1. // MultiStepper.pde
  2. // -*- mode: C++ -*-
  3. // Use MultiStepper class to manage multiple steppers and make them all move to
  4. // the same position at the same time for linear 2d (or 3d) motion.
  5. #include <AccelStepper.h>
  6. #include <MultiStepper.h>
  7. // EG X-Y position bed driven by 2 steppers
  8. // Alas its not possible to build an array of these with different pins for each :-(
  9. AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 3, 4, 5);
  10. AccelStepper stepper2(AccelStepper::FULL4WIRE, 8, 9, 10, 11);
  11. // Up to 10 steppers can be handled as a group by MultiStepper
  12. MultiStepper steppers;
  13. void setup() {
  14. Serial.begin(9600);
  15. // Configure each stepper
  16. stepper1.setMaxSpeed(100);
  17. stepper2.setMaxSpeed(100);
  18. // Then give them to MultiStepper to manage
  19. steppers.addStepper(stepper1);
  20. steppers.addStepper(stepper2);
  21. }
  22. void loop() {
  23. long positions[2]; // Array of desired stepper positions
  24. positions[0] = 1000;
  25. positions[1] = 50;
  26. steppers.moveTo(positions);
  27. steppers.runSpeedToPosition(); // Blocks until all are in position
  28. delay(1000);
  29. // Move to a different coordinate
  30. positions[0] = -100;
  31. positions[1] = 100;
  32. steppers.moveTo(positions);
  33. steppers.runSpeedToPosition(); // Blocks until all are in position
  34. delay(1000);
  35. }