root / arduino-1.0 / libraries / Stepper / Stepper.h @ 58d82c77
History | View | Annotate | Download (2.44 KB)
1 |
/*
|
---|---|
2 |
Stepper.h - - Stepper library for Wiring/Arduino - Version 0.4
|
3 |
|
4 |
Original library (0.1) by Tom Igoe.
|
5 |
Two-wire modifications (0.2) by Sebastian Gassner
|
6 |
Combination version (0.3) by Tom Igoe and David Mellis
|
7 |
Bug fix for four-wire (0.4) by Tom Igoe, bug fix from Noah Shibley
|
8 |
|
9 |
Drives a unipolar or bipolar stepper motor using 2 wires or 4 wires
|
10 |
|
11 |
When wiring multiple stepper motors to a microcontroller,
|
12 |
you quickly run out of output pins, with each motor requiring 4 connections.
|
13 |
|
14 |
By making use of the fact that at any time two of the four motor
|
15 |
coils are the inverse of the other two, the number of
|
16 |
control connections can be reduced from 4 to 2.
|
17 |
|
18 |
A slightly modified circuit around a Darlington transistor array or an L293 H-bridge
|
19 |
connects to only 2 microcontroler pins, inverts the signals received,
|
20 |
and delivers the 4 (2 plus 2 inverted ones) output signals required
|
21 |
for driving a stepper motor.
|
22 |
|
23 |
The sequence of control signals for 4 control wires is as follows:
|
24 |
|
25 |
Step C0 C1 C2 C3
|
26 |
1 1 0 1 0
|
27 |
2 0 1 1 0
|
28 |
3 0 1 0 1
|
29 |
4 1 0 0 1
|
30 |
|
31 |
The sequence of controls signals for 2 control wires is as follows
|
32 |
(columns C1 and C2 from above):
|
33 |
|
34 |
Step C0 C1
|
35 |
1 0 1
|
36 |
2 1 1
|
37 |
3 1 0
|
38 |
4 0 0
|
39 |
|
40 |
The circuits can be found at
|
41 |
http://www.arduino.cc/en/Tutorial/Stepper
|
42 |
*/
|
43 |
|
44 |
// ensure this library description is only included once
|
45 |
#ifndef Stepper_h
|
46 |
#define Stepper_h
|
47 |
|
48 |
// library interface description
|
49 |
class Stepper { |
50 |
public:
|
51 |
// constructors:
|
52 |
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2); |
53 |
Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4); |
54 |
|
55 |
// speed setter method:
|
56 |
void setSpeed(long whatSpeed); |
57 |
|
58 |
// mover method:
|
59 |
void step(int number_of_steps); |
60 |
|
61 |
int version(void); |
62 |
|
63 |
private:
|
64 |
void stepMotor(int this_step); |
65 |
|
66 |
int direction; // Direction of rotation |
67 |
int speed; // Speed in RPMs |
68 |
unsigned long step_delay; // delay between steps, in ms, based on speed |
69 |
int number_of_steps; // total number of steps this motor can take |
70 |
int pin_count; // whether you're driving the motor with 2 or 4 pins |
71 |
int step_number; // which step the motor is on |
72 |
|
73 |
// motor pin numbers:
|
74 |
int motor_pin_1;
|
75 |
int motor_pin_2;
|
76 |
int motor_pin_3;
|
77 |
int motor_pin_4;
|
78 |
|
79 |
long last_step_time; // time stamp in ms of when the last step was taken |
80 |
}; |
81 |
|
82 |
#endif
|
83 |
|