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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
| #include <AccelStepper.h>
const int stepsPerRevolution = 2048; // there are 2048 steps for one rotation of the 28BYJ-48 shaft
#define HALFSTEP 8 // Nécessaire au bon fonctionnement du moteur
#define LEDoccupe A3
#define LEDok A1
int FiltreUtilise = 0;
int homepin = A2;
// Motor pin definitions
#define motorPin1 8 // IN1 on UL2003
#define motorPin2 9 // IN2 on UL2003
#define motorPin3 10 // IN3 on UL2003
#define motorPin4 11 // IN4 on UL2003
// Initialisation de la sequence des pins IN1-IN3-IN2-IN4
AccelStepper Moteur1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
void setup() {
Moteur1.setAcceleration(3000.0);// Acceleration Max du moteur A PARAMETRER
Moteur1.setMaxSpeed(5000.0); // Vitesse Max du moteur A PARAMETRER
Moteur1.setCurrentPosition(0);
Serial.flush();
Serial.begin(9600); // Doit correspondre à votre driver ASCOM A PARAMETRER
pinMode(homepin, INPUT);
analogWrite(LEDok,1023);
analogWrite(LEDoccupe,1023);
delay(500);
analogWrite(LEDok,0);
analogWrite(LEDoccupe,0);
}
void loop() {
String cmd;
if (Serial.available() >0) {
cmd = Serial.readStringUntil('#');
if (cmd=="QUELFILTRE") {
Serial.print(FiltreUtilise); Serial.println("#");
}
else if (cmd=="FILTRE0") ChangeFiltre(0);
else if (cmd=="FILTRE1") ChangeFiltre(1);
else if (cmd=="FILTRE2") ChangeFiltre(2);
else if (cmd=="FILTRE3") ChangeFiltre(3);
else if (cmd=="FILTRE4") ChangeFiltre(4);
else if (cmd=="HOME") ChangeFiltre(5);
}
}
void MoteurOFF() {
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
void ChangeFiltre(int pos)
{
FiltreUtilise = pos;
switch (FiltreUtilise)
{
case 0: // DEPLACEMENT FILTRE 1
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
Moteur1.run();
Moteur1.runToNewPosition(FiltreUtilise * 6250); // 6250= Distance entre chaque filtre en nbre pas 360°/5 A PARAMETRER
Serial.print(FiltreUtilise); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
MoteurOFF();
break;
case 1: // DEPLACEMENT FILTRE 2
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
Moteur1.run();
Moteur1.runToNewPosition(FiltreUtilise * 6250); // 6250= Distance entre chaque filtre en nbre pas 360°/5 A PARAMETRER
Serial.print(FiltreUtilise); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
case 2: // DEPLACEMENT FILTRE 3
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
Moteur1.run();
Moteur1.runToNewPosition(FiltreUtilise * 6250); // 6250= Distance entre chaque filtre en nbre pas 360°/5 A PARAMETRER
Serial.print(FiltreUtilise); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
case 3: // // DEPLACEMENT FILTRE 4
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
Moteur1.run();
Moteur1.runToNewPosition(FiltreUtilise * 6250); // 6250= Distance entre chaque filtre en nbre pas 360°/5 A PARAMETRER
Serial.print(FiltreUtilise); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
case 4: // DEPLACEMENT FILTRE 5
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
Moteur1.run();
Moteur1.runToNewPosition(FiltreUtilise * 6250); // 6250= Distance entre chaque filtre en nbre pas 360°/5 A PARAMETRER
Serial.print(FiltreUtilise); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
case 5: // DEPLACEMENT HOME
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
while(digitalRead(homepin) == LOW) // switch not yet triggered/home
{
Moteur1.move(+Moteur1.currentPosition()); // then continue to move in clockwise direction
Moteur1.run();
delay(2);
}
delay (100);// for testing will remove once all ok
Moteur1.setCurrentPosition(0); // once homePin == LOW, reset currentPosition to 0
//Moteur1.runToNewPosition(FiltreUtilise * 6250); // 6250= Distance entre chaque filtre en nbre pas 360°/5 A PARAMETRER
Serial.print(FiltreUtilise); Serial.println("RaF SUR POSITION HOME");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
}
} |