CNC Shield - A4988 TMC2209

Управление CNC Shield - A4988 TMC2209
 long stepn52 = 0;
 long spedn52 = 0;
 long stepn63 = 0;
 long spedn63 = 0;
 long stepn74 = 0;
 long spedn74 = 0;


void setup() {
   pinMode(5, OUTPUT);
   pinMode(2, OUTPUT);
   pinMode(6, OUTPUT);
   pinMode(3, OUTPUT);
   pinMode(7, OUTPUT);
   pinMode(4, OUTPUT);
}

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

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

     stepn74 = 1000;
     spedn74 = 150;
       if (stepn74 < 0 && spedn74 > 0){
         stepn74 = stepn74*-1;
         for (int count = 0; count < stepn74; count++) {
           digitalWrite(7, 0);
           digitalWrite(4, 1);
           delayMicroseconds(map(spedn74, 100, 1, 4000, 10000));
           digitalWrite(4, 0);
           delayMicroseconds(map(spedn74, 100, 1, 4000, 10000));
         }
        stepn74 = stepn74*-1;
          }
       if (stepn74 > 0 && spedn74 > 0){
         for (int count = 0; count < stepn74; count++) {
           digitalWrite(7, 1);
           digitalWrite(4, 1);
           delayMicroseconds(map(spedn74, 100, 1, 4000, 10000));
           digitalWrite(4, 0);
           delayMicroseconds(map(spedn74, 100, 1, 4000, 10000));
         }
          }
       if (stepn74 == 0 | spedn74 == 0){
           digitalWrite(7, 0);
           digitalWrite(4, 0);
          }
} 

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



Видеоурок: