summaryrefslogtreecommitdiff
path: root/Arduino/libraries/AccelStepper/examples/Random
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/Random
parent869e68986aa8f69af6e7842260a68d1e5c6f796f (diff)
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'Arduino/libraries/AccelStepper/examples/Random')
-rw-r--r--Arduino/libraries/AccelStepper/examples/Random/Random.pde30
1 files changed, 30 insertions, 0 deletions
diff --git a/Arduino/libraries/AccelStepper/examples/Random/Random.pde b/Arduino/libraries/AccelStepper/examples/Random/Random.pde
new file mode 100644
index 0000000..871d361
--- /dev/null
+++ b/Arduino/libraries/AccelStepper/examples/Random/Random.pde
@@ -0,0 +1,30 @@
+// Random.pde
+// -*- mode: C++ -*-
+//
+// Make a single stepper perform random changes in speed, position and acceleration
+//
+// Copyright (C) 2009 Mike McCauley
+// $Id: Random.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
+
+#include <AccelStepper.h>
+
+// Define a stepper and the pins it will use
+AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
+
+void setup()
+{
+}
+
+void loop()
+{
+ if (stepper.distanceToGo() == 0)
+ {
+ // Random change to speed, position and acceleration
+ // Make sure we dont get 0 speed or accelerations
+ delay(1000);
+ stepper.moveTo(rand() % 200);
+ stepper.setMaxSpeed((rand() % 200) + 1);
+ stepper.setAcceleration((rand() % 200) + 1);
+ }
+ stepper.run();
+}