1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <Stepper.h>
// Configuration des moteurs pas à pas
const int pasParTour = 200; // Le nombre de pas par tour pour les moteurs pas à pas
const int moteurAPins[] = {3, 4, 5, 6};
const int moteurBPins[] = {7, 8, 11, 12};
const int moteurCPin = 2;
// Configuration des fins de course et des boutons poussoirs
const int bp1Pin = A0;
const int bp2Pin = A1;
const int fdc1Pin = A2;
const int fdc2Pin = A3;
const int fdc3Pin = A4;
const int fdc4Pin = A5;
// Créer des objets Stepper pour les moteurs pas à pas
Stepper moteurA(pasParTour, moteurAPins[0], moteurAPins[1], moteurAPins[2], moteurAPins[3]);
Stepper moteurB(pasParTour, moteurBPins[0], moteurBPins[1], moteurBPins[2], moteurBPins[3]);
// Temps pour le moteur C en millisecondes
const unsigned long tempsMoteurC = 180000; // 3 minutes
void setup() {
pinMode(bp1Pin, INPUT);
pinMode(bp2Pin, INPUT);
pinMode(fdc1Pin, INPUT);
pinMode(fdc2Pin, INPUT);
pinMode(fdc3Pin, INPUT);
pinMode(fdc4Pin, INPUT);
// Initialiser les pins des moteurs pas à pas
for (int i = 0; i < 4; i++) {
pinMode(moteurAPins[i], OUTPUT);
pinMode(moteurBPins[i], OUTPUT);
}
pinMode(moteurCPin, OUTPUT);
}
void loop() {
// Attendre l'appui sur le bouton poussoir bp1
while (digitalRead(bp1Pin) == HIGH) {
// Attente
}
// Séquence montée du moteur A jusqu'au Fdc2
while (digitalRead(fdc2Pin) == HIGH) {
moteurA.setSpeed(100);
moteurA.step(-1);
}
moteurA.setSpeed(0);
// Rotation du moteur B jusqu'au Fdc4
while (digitalRead(fdc4Pin) == HIGH) {
moteurB.setSpeed(100);
moteurB.step(1);
}
moteurB.setSpeed(0);
// Descente du moteur A jusqu'au Fdc1
while (digitalRead(fdc1Pin) == HIGH) {
moteurA.setSpeed(100);
moteurA.step(1);
}
moteurA.setSpeed(0);
// Activation du moteur C pendant le temps défini
unsigned long startTime = millis();
digitalWrite(moteurCPin, HIGH);
while (millis() - startTime < tempsMoteurC) {
// Attente
}
digitalWrite(moteurCPin, LOW);
// Montée du moteur A jusqu'au Fdc2
while (digitalRead(fdc2Pin) == HIGH) {
moteurA.setSpeed(100);
moteurA.step(-1);
}
moteurA.setSpeed(0);
// Rotation du moteur B jusqu'au Fdc3
while (digitalRead(fdc3Pin) == HIGH) {
moteurB.setSpeed(100);
moteurB.step(1);
}
moteurB.setSpeed(0);
// Descente du moteur A jusqu'au Fdc1
while (digitalRead(fdc1Pin) == HIGH) {
moteurA.setSpeed(100);
moteurA.step(1);
}
moteurA.setSpeed(0);
} |
Partager