I have a lot of problems with a variable and my step-by-step engine. Indeed, I would like to enter a number between 0 and 7 in the monitor and the motor turn on and go to the position choosen and come back where it was, at the first position (0).
But it prints three différent values of x. The first is the good one but the two other shouldn't be printed.
Here is the code :
#include <Stepper.h> // utilisation d'une bibliothèque pour moteur pas à pas
int x=0;
const int NombrePas = 64;
const int Pas_1 = 2;
const int Pas_2 = 3;
const int Pas_3 = 4;
const int Pas_4 = 5;
Stepper stepper(NombrePas, Pas_1, Pas_3, Pas_2, Pas_4);
void setup() {
Serial.begin(9600); // connection au moniteur série
stepper.setSpeed(400); // vitesse du moteur
pinMode(Pas_1, OUTPUT);
pinMode(Pas_2, OUTPUT);
pinMode(Pas_3, OUTPUT);
pinMode(Pas_4, OUTPUT);
}
void loop() {
x=Serial.read(); // -48 car en ascii
if (x!=-1) {
Serial.print("la case sélectionnée est : ");
Serial.println(x-48);
Serial.println("bite");
x=-1;
}
// stepper.step(256 * x); // le nombre de pas que le moteur effectue
// delay(2000);
// stepper.step(-256 * x);
// delay(2000);
}
Sorry it's in french but you should understand. If not please told me!
Thanks a lot