Curieux que le nombre de pas (6400) change la vitesse ...
Testez ceci (sans garantie), la commande est en mettant la broche 4 au GND
int PUL=7; //define Pulse pin
int DIR=6; //define Direction pin
int ENA=5; //define Enable Pin
int RUN=4; //define appui Pin
int appui=0; // sur le bouton
int sens=0; // sens 0, 1
void setup() {
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
pinMode (ENA, OUTPUT);
pinMode (RUN, INPUT_PULLUP);
}
void loop() {
appui = digitalRead (RUN);
if (appui == 0) {
if (sens == 0) {
aller();
}
else {
retour();
}
}
}
void aller(){
for (int i=0; i<100; i++) //Forward 100 steps
{
digitalWrite(DIR,LOW);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
sens = 1;
}
void retour(){
for (int i=0; i<100; i++) //Backward 100 steps
{
digitalWrite(DIR,HIGH);
digitalWrite(ENA,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
sens = 0;
}