Basic Library
Digital I/O
            Analog I/O
            Advanced I/O
            Time
            Math
            Trigonometry
            Random Numbers
            Bits and Bytes
            Interrupts
            Serial Comm.
Standard Library
Camera
            Servo Motor
            Stepping Motor
            Character LCD
            SPI
            I2C (Wire)
            SD Card
            SD (File Operations)
            Periodic Operation
            Clock (RTC)
Mbed Tips
Stepping Motor (Stepper Class)
This library enables control of stepping motors connected to the GR-LYCHEE board. To use, specify #include <stepper.h>.
Stepper()
- Description
- This constructor creates Stepper Class instances.
- Syntax
- Stepper(steps, pin1, pin2)
 Stepper(steps, pin1, pin2, pin3, pin4)
- Parameters
- steps: The number of steps in one revolution (360 degrees) of the motor. 100 indicates 3.6 degrees per step. (int)
 pins 1 - 4: Pins for connection to a motor.
- Returns
- None
setSpeed
- Description
- Sets the motor speed in rotations per minute (RPMs).
- Syntax
- setSpeed(long rpms)
- Parameters
- rpms: The speed at which the motor should turn in rotations per minute [rpm]
- Returns
- None
step
- Description
- Turns the motor a specific number of steps.
- Syntax
- step(int steps)
- Parameters
- steps: The number of steps to turn the motor - positive to turn one direction, negative to turn the other
- Returns
- None
Sample Program
#include <Arduino.h>
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 100
    
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);
    
// the previous reading from the analog input
int previous = 0;
    
void setup()
{
    // set the speed of the motor to 30 RPMs
    stepper.setSpeed(30);
}
    
void loop()
{
    // get the sensor value
    int val = analogRead(A0);
    
    // move a number of steps equal to the change in the
    // sensor reading
    stepper.step(val - previous);
    
    // remember the previous value of the sensor
    previous = val;
}