Skip to content

Commit 60e4991

Browse files
committed
Stepper library to the new format
1 parent 6fc7348 commit 60e4991

File tree

8 files changed

+518
-0
lines changed

8 files changed

+518
-0
lines changed

examples/MotorKnob/MotorKnob.ino

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/*
3+
Stepper Motor Control - one revolution
4+
5+
This program drives a unipolar or bipolar stepper motor.
6+
The motor is attached to digital pins 8 - 11 of the Arduino.
7+
8+
The motor should revolve one revolution in one direction, then
9+
one revolution in the other direction.
10+
11+
12+
Created 11 Mar. 2007
13+
Modified 30 Nov. 2009
14+
by Tom Igoe
15+
16+
*/
17+
18+
#include <Stepper.h>
19+
20+
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
21+
// for your motor
22+
23+
// initialize the stepper library on pins 8 through 11:
24+
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
25+
26+
void setup() {
27+
// set the speed at 60 rpm:
28+
myStepper.setSpeed(60);
29+
// initialize the serial port:
30+
Serial.begin(9600);
31+
}
32+
33+
void loop() {
34+
// step one revolution in one direction:
35+
Serial.println("clockwise");
36+
myStepper.step(stepsPerRevolution);
37+
delay(500);
38+
39+
// step one revolution in the other direction:
40+
Serial.println("counterclockwise");
41+
myStepper.step(-stepsPerRevolution);
42+
delay(500);
43+
}
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/*
3+
Stepper Motor Control - one step at a time
4+
5+
This program drives a unipolar or bipolar stepper motor.
6+
The motor is attached to digital pins 8 - 11 of the Arduino.
7+
8+
The motor will step one step at a time, very slowly. You can use this to
9+
test that you've got the four wires of your stepper wired to the correct
10+
pins. If wired correctly, all steps should be in the same direction.
11+
12+
Use this also to count the number of steps per revolution of your motor,
13+
if you don't know it. Then plug that number into the oneRevolution
14+
example to see if you got it right.
15+
16+
Created 30 Nov. 2009
17+
by Tom Igoe
18+
19+
*/
20+
21+
#include <Stepper.h>
22+
23+
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
24+
// for your motor
25+
26+
// initialize the stepper library on pins 8 through 11:
27+
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
28+
29+
int stepCount = 0; // number of steps the motor has taken
30+
31+
void setup() {
32+
// initialize the serial port:
33+
Serial.begin(9600);
34+
}
35+
36+
void loop() {
37+
// step one step:
38+
myStepper.step(1);
39+
Serial.print("steps:" );
40+
Serial.println(stepCount);
41+
stepCount++;
42+
delay(500);
43+
}
44+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
/*
3+
Stepper Motor Control - speed control
4+
5+
This program drives a unipolar or bipolar stepper motor.
6+
The motor is attached to digital pins 8 - 11 of the Arduino.
7+
A potentiometer is connected to analog input 0.
8+
9+
The motor will rotate in a clockwise direction. The higher the potentiometer value,
10+
the faster the motor speed. Because setSpeed() sets the delay between steps,
11+
you may notice the motor is less responsive to changes in the sensor value at
12+
low speeds.
13+
14+
Created 30 Nov. 2009
15+
Modified 28 Oct 2010
16+
by Tom Igoe
17+
18+
*/
19+
20+
#include <Stepper.h>
21+
22+
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
23+
// for your motor
24+
25+
26+
// initialize the stepper library on pins 8 through 11:
27+
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
28+
29+
int stepCount = 0; // number of steps the motor has taken
30+
31+
void setup() {
32+
// nothing to do inside the setup
33+
}
34+
35+
void loop() {
36+
// read the sensor value:
37+
int sensorReading = analogRead(A0);
38+
// map it to a range from 0 to 100:
39+
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
40+
// set the motor speed:
41+
if (motorSpeed > 0) {
42+
myStepper.setSpeed(motorSpeed);
43+
// step 1/100 of a revolution:
44+
myStepper.step(stepsPerRevolution/100);
45+
}
46+
}
47+
48+

keywords.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#######################################
2+
# Syntax Coloring Map For Test
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
Stepper KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
step KEYWORD2
16+
setSpeed KEYWORD2
17+
version KEYWORD2
18+
19+
######################################
20+
# Instances (KEYWORD2)
21+
#######################################
22+
direction KEYWORD2
23+
speed KEYWORD2
24+
25+
26+
#######################################
27+
# Constants (LITERAL1)
28+
#######################################

library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=Stepper
2+
author= Tom Igoe
3+
4+
sentence=Drives a unipolar or bipolar stepper motor using 2 wires or 4 wires
5+
paragraph=This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it.
6+
url=http://arduino.cc/en/Reference/Stepper
7+
architectures=*
8+
version=0.4
9+
dependencies= none
10+
core-dependencies=arduino (>=1.5.0)

0 commit comments

Comments
 (0)