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;
}
}