Bonjour à tous,
Je suis actuellement sur le déplacement d'un moteur Pas à Pas avec un motor shield R3, j'arrive à le faire tourner simplement dans un sens et dans l'autre avec ce code:
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on the motor shield
Stepper myStepper(stepsPerRevolution, 12,13);
// give the motor control pins names:
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
int x = 0;
void setup() {
Serial.begin(9600);
// set the PWM and brake pins so that the direction pins // can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
// initialize the serial port:
Serial.begin(9600);
// set the motor speed (for multiple steps only):
myStepper.setSpeed(40);
}
void loop() {
myStepper.step(400);
delay(2000);
myStepper.step(-400);
delay(2000);
}
Mais lorsque je souhaite compliquer la chose un soucis se présente, je souhaite faire un déplacement d'un pas déposer une goutte, un pas une goutte ( ça X fois) et revenir au début de ma ligne ainsi formée voici mon code :
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
const int stepsInImpresion=1;
// for your motor
// initialize the stepper library on the motor shield
Stepper myStepper(stepsPerRevolution, 12, 13);
// give the motor control pins names:
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;
const int Piezo = 7;
const int ButPin = 4;
int buttonState=0;
int k =0;
int longueurLigne=2;
void setup() {
Serial.begin(9600);
// set the PWM and brake pins so that the direction pins // can be used to control the motor:
pinMode(Piezo, OUTPUT);
pinMode(ButPin, INPUT_PULLUP);
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
// set the motor speed (for multiple steps only):
myStepper.setSpeed(40);
}
void loop()
{
buttonState = digitalRead(ButPin);
if (buttonState == HIGH) {
for (k = 1; k = longueurLigne; 1)
{
// envoie un créneau sur le piézo=demande de goutte d'encre
digitalWrite(Piezo, HIGH);
delay(2);
digitalWrite(Piezo, LOW);
delay(500);
myStepper.step(stepsInImpresion);// après le dépot d'une goutte on bouge un peux pour la suivante(1 pas)
}
myStepper.step((-2*stepsInImpresion)); // retour en début de ligne
}
}
Ici la boucle k tourne un grand nombre de fois alors que elle devrait tourner 2 fois et revenir au digitalread, des idées ?