lunes, 23 de junio de 2014

Arduino - Motor Paso a Paso Bipolar

Motor Paso a Paso Bipolar

Codigo ejemplo:

 int Pin0 = 8;
 int Pin1 = 9;
 int Pin2 = 10;
 int Pin3 = 11;
 int _step = 0;
 int pases=0;
 boolean dir = false;// change the direction of the motor
 void setup()
 {
  pinMode(Pin0, OUTPUT); 
  pinMode(Pin1, OUTPUT); 
  pinMode(Pin2, OUTPUT); 
  pinMode(Pin3, OUTPUT); 
  Serial.begin(9600);
 }
   void loop()
 {
   for(pases=0;pases<4075;pases++){
     pas();
     delay(1);  // change this delay to control the speed of your stepper, delay to 100 you can see the signal LEDs blinking.
   }
   delay(500);
 }

 void pas()
 {
   switch(_step){
    case 0:
      digitalWrite(Pin0, LOW); 
      digitalWrite(Pin1, LOW);
      digitalWrite(Pin2, LOW);
      digitalWrite(Pin3, HIGH);
    break; 
    case 1:
      digitalWrite(Pin0, LOW); 
      digitalWrite(Pin1, LOW);
      digitalWrite(Pin2, HIGH);
      digitalWrite(Pin3, HIGH);
    break; 
    case 2:
      digitalWrite(Pin0, LOW); 
      digitalWrite(Pin1, LOW);
      digitalWrite(Pin2, HIGH);
      digitalWrite(Pin3, LOW);
    break; 
    case 3:
      digitalWrite(Pin0, LOW); 
      digitalWrite(Pin1, HIGH);
      digitalWrite(Pin2, HIGH);
      digitalWrite(Pin3, LOW);
    break; 
    case 4:
      digitalWrite(Pin0, LOW); 
      digitalWrite(Pin1, HIGH);
      digitalWrite(Pin2, LOW);
      digitalWrite(Pin3, LOW);
    break; 
    case 5:
      digitalWrite(Pin0, HIGH); 
      digitalWrite(Pin1, HIGH);
      digitalWrite(Pin2, LOW);
      digitalWrite(Pin3, LOW);
    break; 
      case 6:
      digitalWrite(Pin0, HIGH); 
      digitalWrite(Pin1, LOW);
      digitalWrite(Pin2, LOW);
      digitalWrite(Pin3, LOW);
    break; 
    case 7:
      digitalWrite(Pin0, HIGH); 
      digitalWrite(Pin1, LOW);
      digitalWrite(Pin2, LOW);
      digitalWrite(Pin3, HIGH);
    break; 
    default:
      digitalWrite(Pin0, LOW); 
      digitalWrite(Pin1, LOW);
      digitalWrite(Pin2, LOW);
      digitalWrite(Pin3, LOW);
    break; 
  }
  if(dir){     _step++; ;  }else{     _step--;   }
  if(_step>7){     _step=0;   }
  if(_step<0){     _step=7;   }
 }

No hay comentarios :

Publicar un comentario