summaryrefslogtreecommitdiff
path: root/Arduino/libraries/AccelStepper/examples/MultiStepper/MultiStepper.pde
diff options
context:
space:
mode:
authorCarlos Maiolino <[email protected]>2025-07-10 22:55:07 +0200
committerCarlos Maiolino <[email protected]>2025-07-10 22:56:55 +0200
commitd98f46ce647846b0aa30b2e16a30fd4e152a1bf5 (patch)
tree267474fcc77cf20b428f6f4c7f768ca09f4cfe0e /Arduino/libraries/AccelStepper/examples/MultiStepper/MultiStepper.pde
parent869e68986aa8f69af6e7842260a68d1e5c6f796f (diff)
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'Arduino/libraries/AccelStepper/examples/MultiStepper/MultiStepper.pde')
-rw-r--r--Arduino/libraries/AccelStepper/examples/MultiStepper/MultiStepper.pde44
1 files changed, 44 insertions, 0 deletions
diff --git a/Arduino/libraries/AccelStepper/examples/MultiStepper/MultiStepper.pde b/Arduino/libraries/AccelStepper/examples/MultiStepper/MultiStepper.pde
new file mode 100644
index 0000000..386c784
--- /dev/null
+++ b/Arduino/libraries/AccelStepper/examples/MultiStepper/MultiStepper.pde
@@ -0,0 +1,44 @@
+// MultiStepper.pde
+// -*- mode: C++ -*-
+// Use MultiStepper class to manage multiple steppers and make them all move to
+// the same position at the same time for linear 2d (or 3d) motion.
+
+#include <AccelStepper.h>
+#include <MultiStepper.h>
+
+// EG X-Y position bed driven by 2 steppers
+// Alas its not possible to build an array of these with different pins for each :-(
+AccelStepper stepper1(AccelStepper::FULL4WIRE, 2, 3, 4, 5);
+AccelStepper stepper2(AccelStepper::FULL4WIRE, 8, 9, 10, 11);
+
+// Up to 10 steppers can be handled as a group by MultiStepper
+MultiStepper steppers;
+
+void setup() {
+ Serial.begin(9600);
+
+ // Configure each stepper
+ stepper1.setMaxSpeed(100);
+ stepper2.setMaxSpeed(100);
+
+ // Then give them to MultiStepper to manage
+ steppers.addStepper(stepper1);
+ steppers.addStepper(stepper2);
+}
+
+void loop() {
+ long positions[2]; // Array of desired stepper positions
+
+ positions[0] = 1000;
+ positions[1] = 50;
+ steppers.moveTo(positions);
+ steppers.runSpeedToPosition(); // Blocks until all are in position
+ delay(1000);
+
+ // Move to a different coordinate
+ positions[0] = -100;
+ positions[1] = 100;
+ steppers.moveTo(positions);
+ steppers.runSpeedToPosition(); // Blocks until all are in position
+ delay(1000);
+}