// Stepper Motor Sequences
// by Juan Manuel González V.

// Demonstrates the use of a TEAC stepper motor.
// TEAC motors rotate 360º in 50 cycles (steps).

// Created 15 November 2005 
// Updated 2 April 2006

void setup()
{
  int i;
  for(i=0; i<3; i++) {        //Analog pins for yellow, red,
    pinMode(i, OUTPUT);       //blue and white wires of the motor.
  }

  pinMode(48, OUTPUT);        //Wiring led pin 48.
  digitalWrite(48, HIGH);
}


void stepforward()            //Drive sequence for one cycle going 
{                             //forward.         
  digitalWrite(0, HIGH);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  delay(30);
  digitalWrite(0, LOW);
  digitalWrite(1, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  delay(30);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  delay(30);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  delay(30);
}

void stepbackward()            //Drive sequence for one cycle going    
{                              //backward.
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  delay(30);
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  delay(30);
  digitalWrite(0, LOW);
  digitalWrite(1, HIGH);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  delay(30);
  digitalWrite(0, HIGH);
  digitalWrite(1, LOW);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  delay(30);
}

void loop()
{
  stepforward();         //Repeats the required sequence over & 
  //over to make the motor turn continuously FW.
  //stepbackward();        //Repeats the required sequence over &
  //over to make the motor turn continuously BW.
}
