Helping me to understand what exactly this code is explained?

int STEP = 5;
int DIR = 2;
int n;
int k;
int duree_pas; // durée d’un pas en us

void setup() {
// put your setup code here, to run once:
pinMode(STEP, OUTPUT);
pinMode(DIR, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
// n is equivalent to distance, where n=500 equals to =4cm
// duree_pas = time (milisecond)
n=0;
digitalWrite(DIR, 0);
duree_pas = 400;
while (n < 200) {
digitalWrite(STEP, 1);
delayMicroseconds(duree_pas / 2);
digitalWrite(STEP, 0);
delayMicroseconds(duree_pas / 2);
n = n + 1;
}
n=0;
digitalWrite(DIR, 1);
duree_pas= 400;
while (n < 500) {
digitalWrite(STEP, 1);
delayMicroseconds(duree_pas / 2);
digitalWrite(STEP, 0);
delayMicroseconds(duree_pas / 2);
n = n + 1;
}
}

Please see the sticky topics on top of the forum, how to format and present code.

It looks like a stepper motor test program.

You may get better assistance in the French forum section?

for loops have been implemented for C++.
They’re very popular, I’m told.

1 Like