martedì 23 dicembre 2014

Motori passo passo (stepper ) 3a parte.

  const int buttonAvanti   = 2;
  const int buttonIndietro = 4;

  
  int StateAvanti   = 0;  
  int StateIndietro = 0;  
  
  int motorPin1 = 8;
  int motorPin2 = 9;
  int motorPin3 = 10;
  int motorPin4 = 11;
  int delayTime = 3;
     
   
  void setup()
      { pinMode(motorPin1, OUTPUT);
        pinMode(motorPin2, OUTPUT);
        pinMode(motorPin3, OUTPUT);
        pinMode(motorPin4, OUTPUT); 
        pinMode(buttonAvanti, INPUT);
        pinMode(buttonIndietro, INPUT);  }
       
  void loop() { //----INIZIO LOOP-----
         
       StateAvanti = digitalRead(buttonAvanti);
             if   ( StateAvanti == HIGH)
                  { MotoreAvanti();    } 
   
       
       StateIndietro = digitalRead(buttonIndietro);
             if   ( StateIndietro == HIGH)
                  { MotoreIndietro();    } 

   }//------------------FINE LOOP-------
       
      
      //--------- ROUTINE DI RICHIAMO-----------
   void MotoreAvanti() {
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(delayTime);
        
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(delayTime);
        
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, LOW);
        delay(delayTime);
       
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, HIGH);
        delay(delayTime); }

         //--------- ROUTINE DI RICHIAMO-----------
   void MotoreIndietro() {
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, HIGH);
        delay(delayTime);
        
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, LOW);
        delay(delayTime);
        
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(delayTime);
       
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(delayTime); }  

   
   }

Nessun commento:

Posta un commento