Saltar la navegación

Otro ejemplo

Otro ejemplo

//original source is http://www.geeetech.com/wiki/index.php/Stepper_Motor_5V_4-Phase_5-Wire_%26_ULN2003_Driver_Board_for_Arduino

// Update by Ahmad Shamshiri for RoboJax.com

// Published on March 27, 2017 in Aajx, ON, Canada.

// hecho con variable _step y switch

int Pin1 = 2;

int Pin2 = 3;

int Pin3 = 4;

int Pin4 = 5;

int _step = 0;

boolean dir = 1;// false=clockwise, true=counter clockwise, A MI AMB 0 NO ME FUNCIONA!!

int count=0;

void setup()

{

pinMode(Pin1, OUTPUT);

pinMode(Pin2, OUTPUT);

pinMode(Pin3, OUTPUT);

pinMode(Pin4, OUTPUT);

}

void loop()

{

switch(_step){

case 0:

digitalWrite(Pin1, LOW);

digitalWrite(Pin2, LOW);

digitalWrite(Pin3, LOW);

digitalWrite(Pin4, HIGH);

break;

case 1:

digitalWrite(Pin1, LOW);

digitalWrite(Pin2, LOW);

digitalWrite(Pin3, HIGH);

digitalWrite(Pin4, HIGH);

break;

case 2:

digitalWrite(Pin1, LOW);

digitalWrite(Pin2, LOW);

digitalWrite(Pin3, HIGH);

digitalWrite(Pin4, LOW);

break;

case 3:

digitalWrite(Pin1, LOW);

digitalWrite(Pin2, HIGH);

digitalWrite(Pin3, HIGH);

digitalWrite(Pin4, LOW);

break;

case 4:

digitalWrite(Pin1, LOW);

digitalWrite(Pin2, HIGH);

digitalWrite(Pin3, LOW);

digitalWrite(Pin4, LOW);

break;

case 5:

digitalWrite(Pin1, HIGH);

digitalWrite(Pin2, HIGH);

digitalWrite(Pin3, LOW);

digitalWrite(Pin4, LOW);

break;

case 6:

digitalWrite(Pin1, HIGH);

digitalWrite(Pin2, LOW);

digitalWrite(Pin3, LOW);

digitalWrite(Pin4, LOW);

break;

case 7:

digitalWrite(Pin1, HIGH);

digitalWrite(Pin2, LOW);

digitalWrite(Pin3, LOW);

digitalWrite(Pin4, HIGH);

break;

default:

digitalWrite(Pin1, LOW);

digitalWrite(Pin2, LOW);

digitalWrite(Pin3, LOW);

digitalWrite(Pin4, LOW);

break;

}

if(dir){

_step++;

}else{

_step--;

}

if(_step>7){

_step=0;

}

if(_step<0){

_step=7;

}

delay(10);

}