xxxxxxxxxx
COPY
1 #include <Stepper.h>
2
3 // change this to the number of steps on your motor
4 #define STEPS 100
5
6 // create an instance of the stepper class, specifying
7 // the number of steps of the motor and the pins it's
8 // attached to
9 Stepper stepper(STEPS, 8, 9, 10, 11);
10
11 // the previous reading from the analog input
12 int previous = 0;
13
14 void setup() {
15 // set the speed of the motor to 30 RPMs
16 stepper.setSpeed(30);
17 }
18
19 void loop() {
20 // get the sensor value
21 int val = analogRead(0);
22
23 // move a number of steps equal to the change in the
24 // sensor reading
25 stepper.step(val - previous);
26
27 // remember the previous value of the sensor
28 previous = val;
29 }