aboutsummaryrefslogtreecommitdiff
path: root/libraries/Stepper/examples/MotorKnob
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2012-01-04 15:14:51 +0100
committerCristian Maglie <c.maglie@bug.st>2012-01-04 15:14:51 +0100
commit8c2b5b979a75d109ae7cc306afc50d7ffe1e0366 (patch)
tree19ac8d91c7209397e7dc890b432a254ae9a7cd62 /libraries/Stepper/examples/MotorKnob
parentbe52c95820400d48e47615232d3c38236166fad3 (diff)
Moved libraries folder inside platform folder. Now libraries and examples are searched per board/platform
Diffstat (limited to 'libraries/Stepper/examples/MotorKnob')
-rw-r--r--libraries/Stepper/examples/MotorKnob/MotorKnob.ino41
1 files changed, 41 insertions, 0 deletions
diff --git a/libraries/Stepper/examples/MotorKnob/MotorKnob.ino b/libraries/Stepper/examples/MotorKnob/MotorKnob.ino
new file mode 100644
index 0000000..d428186
--- /dev/null
+++ b/libraries/Stepper/examples/MotorKnob/MotorKnob.ino
@@ -0,0 +1,41 @@
+/*
+ * MotorKnob
+ *
+ * A stepper motor follows the turns of a potentiometer
+ * (or other sensor) on analog input 0.
+ *
+ * http://www.arduino.cc/en/Reference/Stepper
+ * This example code is in the public domain.
+ */
+
+#include <Stepper.h>
+
+// change this to the number of steps on your motor
+#define STEPS 100
+
+// create an instance of the stepper class, specifying
+// the number of steps of the motor and the pins it's
+// attached to
+Stepper stepper(STEPS, 8, 9, 10, 11);
+
+// the previous reading from the analog input
+int previous = 0;
+
+void setup()
+{
+ // set the speed of the motor to 30 RPMs
+ stepper.setSpeed(30);
+}
+
+void loop()
+{
+ // get the sensor value
+ int val = analogRead(0);
+
+ // move a number of steps equal to the change in the
+ // sensor reading
+ stepper.step(val - previous);
+
+ // remember the previous value of the sensor
+ previous = val;
+} \ No newline at end of file