1/* 2 * MotorKnob 3 * 4 * A stepper motor follows the turns of a potentiometer 5 * (or other sensor) on analog input 0. 6 * 7 * http://www.arduino.cc/en/Reference/Stepper 8 * This example code is in the public domain. 9 */ 10 11#include 12 13// change this to the number of steps on your motor 14#define STEPS 200 15 16// create an instance of the stepper class, specifying 17// the number of steps of the motor and the pins it's 18// attached to 19Stepper stepper(STEPS, 2, 3, 4, 5); 20 21// the previous reading from the analog input 22int previous = 0; 23 24void setup() { 25 // set the speed of the motor to 90 RPMs 26 stepper.setSpeed(90); 27} 28 29void loop() { 30 // get the sensor value 31 int val = analogRead(0); 32 33 // move a number of steps equal to the change in the 34 // sensor reading 35 stepper.step(val - previous); 36 37 // remember the previous value of the sensor 38 previous = val; 39}