summaryrefslogtreecommitdiff
path: root/Arduino/libraries/AccelStepper/examples/ProportionalControl
diff options
context:
space:
mode:
Diffstat (limited to 'Arduino/libraries/AccelStepper/examples/ProportionalControl')
-rw-r--r--Arduino/libraries/AccelStepper/examples/ProportionalControl/ProportionalControl.pde32
1 files changed, 32 insertions, 0 deletions
diff --git a/Arduino/libraries/AccelStepper/examples/ProportionalControl/ProportionalControl.pde b/Arduino/libraries/AccelStepper/examples/ProportionalControl/ProportionalControl.pde
new file mode 100644
index 0000000..2afe444
--- /dev/null
+++ b/Arduino/libraries/AccelStepper/examples/ProportionalControl/ProportionalControl.pde
@@ -0,0 +1,32 @@
+// ProportionalControl.pde
+// -*- mode: C++ -*-
+//
+// Make a single stepper follow the analog value read from a pot or whatever
+// The stepper will move at a constant speed to each newly set posiiton,
+// depending on the value of the pot.
+//
+// Copyright (C) 2012 Mike McCauley
+// $Id: ProportionalControl.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
+
+// This defines the analog input pin for reading the control voltage
+// Tested with a 10k linear pot between 5v and GND
+#define ANALOG_IN A0
+
+void setup()
+{
+ stepper.setMaxSpeed(1000);
+}
+
+void loop()
+{
+ // Read new position
+ int analog_in = analogRead(ANALOG_IN);
+ stepper.moveTo(analog_in);
+ stepper.setSpeed(100);
+ stepper.runSpeedToPosition();
+}