~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to libraries/Stepper/examples/MotorKnob/MotorKnob.ino

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <Stepper.h>
 
12
 
 
13
// change this to the number of steps on your motor
 
14
#define STEPS 100
 
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
 
19
Stepper stepper(STEPS, 8, 9, 10, 11);
 
20
 
 
21
// the previous reading from the analog input
 
22
int previous = 0;
 
23
 
 
24
void setup()
 
25
{
 
26
  // set the speed of the motor to 30 RPMs
 
27
  stepper.setSpeed(30);
 
28
}
 
29
 
 
30
void loop()
 
31
{
 
32
  // get the sensor value
 
33
  int val = analogRead(0);
 
34
 
 
35
  // move a number of steps equal to the change in the
 
36
  // sensor reading
 
37
  stepper.step(val - previous);
 
38
 
 
39
  // remember the previous value of the sensor
 
40
  previous = val;
 
41
}
 
 
b'\\ No newline at end of file'