Bonjour à tous
Pour un projet de robotique, j'ai besoin que le moteur ( un neman 17 avec un easydriver) face un "home" pour connaitre sa position à la mise sous tension pour qu'il puisse commencer ça boucle.
Pour cela j'ai utilisé la fonction "while" en début de boucle.
Pour la détection j'utilise un Switch NO.
Se qui se passe: le moteur tourne sans arrêt malgré que le switch se ferme, et donc les vrais instructions ne commencent pas.
J'en appelle à vos lumières
Si joint le sketch
Merci de m'avoir lu
A+
int smDirectionPin = 2; //Direction pin
int smStepPin = 3; //Stepper pin
int smBoutonPin = 9; //switch NO pin 9
void setup(){
pinMode(smBoutonPin, INPUT_PULLUP);
digitalWrite(smBoutonPin, LOW);
pinMode(smDirectionPin, OUTPUT);
pinMode(smStepPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
//faire un home
while(smBoutonPin!=LOW)
{
digitalWrite(smDirectionPin, HIGH); //écrit la direction dans EasyDriver (HIGH: sens anti horaire).
/*Slowly turns the motor 1600 steps*/
for (int i = 0; i < 1600; i++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(smStepPin, LOW);
delayMicroseconds(2000);
}
}
delay(1000);
//home touvé avancer d'un demi tour
digitalWrite(smDirectionPin, LOW); //écrit la direction dans EasyDriver (LOW: sens horaire).
/*Turns the motor fast 1600 steps*/
for (int i = 0; i < 800; i++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(800);
digitalWrite(smStepPin, LOW);
delayMicroseconds(800);
}
delay(100);
//commencer la vrai boucle
digitalWrite(smDirectionPin, LOW); //écrit la direction dans EasyDriver (LOW: sens horaire).
/*Slowly turns the motor 1600 steps*/
for (int i = 0; i < 800; i++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(900);
digitalWrite(smStepPin, LOW);
delayMicroseconds(900);
}
delay(1000); //Pauses for a second (the motor does not need to pause between switching direction, so you can safely remove this)
digitalWrite(smDirectionPin, HIGH); //écrit la direction dans EasyDriver (HIGH: sens anti horaire).
/*Turns the motor fast 1600 steps*/
for (int i = 0; i < 800; i++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(900);
digitalWrite(smStepPin, LOW);
delayMicroseconds(900);
}
delay(1000);
}