D:/DRISSI/arduino-0022/arduino-0022/libraries/Stepper/Stepper.h
00001 /*
00002   Stepper.h - - Stepper library for Wiring/Arduino - Version 0.4
00003   
00004   Original library     (0.1) by Tom Igoe.
00005   Two-wire modifications   (0.2) by Sebastian Gassner
00006   Combination version   (0.3) by Tom Igoe and David Mellis
00007   Bug fix for four-wire   (0.4) by Tom Igoe, bug fix from Noah Shibley
00008 
00009   Drives a unipolar or bipolar stepper motor using  2 wires or 4 wires
00010 
00011   When wiring multiple stepper motors to a microcontroller,
00012   you quickly run out of output pins, with each motor requiring 4 connections. 
00013 
00014   By making use of the fact that at any time two of the four motor
00015   coils are the inverse  of the other two, the number of
00016   control connections can be reduced from 4 to 2. 
00017 
00018   A slightly modified circuit around a Darlington transistor array or an L293 H-bridge
00019   connects to only 2 microcontroler pins, inverts the signals received,
00020   and delivers the 4 (2 plus 2 inverted ones) output signals required
00021   for driving a stepper motor.
00022 
00023   The sequence of control signals for 4 control wires is as follows:
00024 
00025   Step C0 C1 C2 C3
00026      1  1  0  1  0
00027      2  0  1  1  0
00028      3  0  1  0  1
00029      4  1  0  0  1
00030 
00031   The sequence of controls signals for 2 control wires is as follows
00032   (columns C1 and C2 from above):
00033 
00034   Step C0 C1
00035      1  0  1
00036      2  1  1
00037      3  1  0
00038      4  0  0
00039 
00040   The circuits can be found at 
00041   http://www.arduino.cc/en/Tutorial/Stepper
00042 */
00043 
00044 // ensure this library description is only included once
00045 #ifndef Stepper_h
00046 #define Stepper_h
00047 
00048 // library interface description
00049 class Stepper {
00050   public:
00051     // constructors:
00052     Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2);
00053     Stepper(int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4);
00054 
00055     // speed setter method:
00056     void setSpeed(long whatSpeed);
00057 
00058     // mover method:
00059     void step(int number_of_steps);
00060 
00061     int version(void);
00062 
00063   private:
00064     void stepMotor(int this_step);
00065     
00066     int direction;        // Direction of rotation
00067     int speed;          // Speed in RPMs
00068     unsigned long step_delay;    // delay between steps, in ms, based on speed
00069     int number_of_steps;      // total number of steps this motor can take
00070     int pin_count;        // whether you're driving the motor with 2 or 4 pins
00071     int step_number;        // which step the motor is on
00072     
00073     // motor pin numbers:
00074     int motor_pin_1;
00075     int motor_pin_2;
00076     int motor_pin_3;
00077     int motor_pin_4;
00078     
00079     long last_step_time;      // time stamp in ms of when the last step was taken
00080 };
00081 
00082 #endif
00083