Шаговый мотор A4988

Управление шаговый мотором через A4988
 long stepn23 = 0;
 long spedn23 = 0;


void setup() {
   pinMode(2, OUTPUT);
   pinMode(3, OUTPUT);
}

void loop() {
       stepn23 = 1000;
       spedn23 = 150;
       if (stepn23 < 0 && spedn23 > 0){
         stepn23 = stepn23*-1;
         for (int count = 0; count < stepn23; count++) {
           digitalWrite(2, 0);
           digitalWrite(3, 1);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
           digitalWrite(3, 0);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
         }
        stepn23 = stepn23*-1;
          }
       if (stepn23 > 0 && spedn23 > 0){
         for (int count = 0; count < stepn23; count++) {
           digitalWrite(2, 1);
           digitalWrite(3, 1);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
           digitalWrite(3, 0);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
         }
          }
       if (stepn23 == 0 | spedn23 == 0){
           digitalWrite(2, 0);
           digitalWrite(3, 0);
          }

       stepn23 = (-1000);
       spedn23 = 150;
       if (stepn23 < 0 && spedn23 > 0){
         stepn23 = stepn23*-1;
         for (int count = 0; count < stepn23; count++) {
           digitalWrite(2, 0);
           digitalWrite(3, 1);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
           digitalWrite(3, 0);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
         }
        stepn23 = stepn23*-1;
          }
       if (stepn23 > 0 && spedn23 > 0){
         for (int count = 0; count < stepn23; count++) {
           digitalWrite(2, 1);
           digitalWrite(3, 1);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
           digitalWrite(3, 0);
           delayMicroseconds(map(spedn23, 100, 1, 4000, 10000));
         }
          }
       if (stepn23 == 0 | spedn23 == 0){
           digitalWrite(2, 0);
           digitalWrite(3, 0);
          }
} 

Открыть пример: Online ArduBlock



Видеоурок:


11 972 просмотров