aboutsummaryrefslogtreecommitdiff
path: root/libraries/Stepper/examples/MotorKnob/MotorKnob.pde
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2007-10-06 13:04:46 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2007-10-06 13:04:46 +0000
commit9e48dfc4fd53a2bc53367568077fbea44f88eda2 (patch)
tree356854e8239e0f0676bcf6105b7ea6a53cb9a880 /libraries/Stepper/examples/MotorKnob/MotorKnob.pde
parent179fcdbda432ff33a921a70994087b08b2a79caa (diff)
Moving libraries out from inside targets and creating bootloaders directory.
Diffstat (limited to 'libraries/Stepper/examples/MotorKnob/MotorKnob.pde')
-rw-r--r--libraries/Stepper/examples/MotorKnob/MotorKnob.pde40
1 files changed, 40 insertions, 0 deletions
diff --git a/libraries/Stepper/examples/MotorKnob/MotorKnob.pde b/libraries/Stepper/examples/MotorKnob/MotorKnob.pde
new file mode 100644
index 0000000..062cac9
--- /dev/null
+++ b/libraries/Stepper/examples/MotorKnob/MotorKnob.pde
@@ -0,0 +1,40 @@
+/*
+ * MotorKnob
+ *
+ * A stepper motor follows the turns of a potentiometer
+ * (or other sensor) on analog input 0.
+ *
+ * http://www.arduino.cc/en/Reference/Stepper
+ */
+
+#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