// Include the AccelStepper library:
//on initialise les temps d'attente

const unsigned long period[198] = {16441, 2115, 4394, 11115, 10134, 11085, 24153, 2326, 17238, 9096, 8462, 11412, 20360, 13134, 5360, 12230, 13096, 15354, 3063, 26400, 24419, 22057, 11192, 9153, 4096, 32221, 8115, 7235, 28346, 12463, 4228, 10141, 10153, 14186, 7384, 13417, 5359, 15057, 13317, 16071, 14176, 14132, 1247, 7363, 13181, 9016, 7000, 11026, 19414, 15076, 22192, 16455, 9416, 19271, 17222, 8126, 9217, 13104, 12384, 7195, 15249, 22307, 6086, 5560, 13345, 11267, 26460, 36075, 11172, 28211, 10296, 16038, 6153, 8433, 7164, 37192, 6111, 16345, 11019, 17057, 22308, 11361, 5446, 4098, 6460, 31433, 17251, 17151, 17268, 17115, 4403, 17172, 12023, 8076, 3400, 18098, 49245, 9406, 24153, 32153, 12441, 14422, 14422, 11000, 6307, 30384, 16076, 10268, 28096, 38057, 20134, 13038, 27441, 7211, 4249, 32054, 24076, 40096, 17172, 5019, 4172, 15328, 14230, 6153, 14408, 18000, 9153, 15225, 24153, 25257, 21085, 23441, 11160, 30134, 26239, 5165, 11422, 5370, 36460, 14076, 16307, 24268, 4364, 38403, 26020, 9243, 24441, 24288, 20096, 12179, 30479, 14307, 14422, 20249, 24371, 27185, 21307, 30307, 28326, 3098, 26076, 15074, 7192, 9441, 24153, 29000, 18000, 8153, 28153, 17115, 8307, 36460, 12053, 12038, 11076, 12326, 8096, 16191, 29384, 20326, 15268, 15468, 10345, 9268, 21345, 37019, 13268, 6326, 23096, 22019, 29172, 29038, 18019, 17211, 9172, 8230, 4172, 15384};

const unsigned long speaker[198] = {14, 30, 19, 31, 2, 11, 14, 3, 11, 14, 30, 19, 5, 19, 31, 21, 14, 11, 10, 19, 14, 21, 31, 11, 2, 19, 14, 8, 19, 11, 7, 4, 10, 11, 2, 14, 3, 10, 19, 5, 4, 19, 7, 8, 7, 19, 14, 8, 11, 19, 14, 30, 21, 19, 3, 4, 11, 21, 9, 14, 19, 11, 30, 11, 2, 4, 21, 19, 30, 11, 30, 14, 5, 31, 8, 14, 9, 21, 3, 9, 10, 11, 19, 2, 14, 19, 9, 19, 14, 2, 3, 14, 5, 2, 7, 14, 19, 14, 2, 19, 11, 30, 7, 3, 10, 19, 14, 9, 11, 19, 14, 19, 14, 5, 14, 19, 11, 19, 7, 19, 14, 19, 14, 3, 11, 30, 31, 7, 19, 11, 19, 2, 14, 19, 11, 14, 30, 8, 14, 11, 14, 11, 2, 11, 14, 5, 19, 14, 11, 30, 19, 14, 8, 9, 14, 19, 10, 19, 14, 8, 2, 19, 9, 14, 11, 19, 9, 2, 19, 2, 14, 11, 8, 14, 2, 19, 21, 11, 19, 4, 30, 9, 14, 11, 7, 19, 11, 9, 19, 30, 19, 11, 14, 19, 14, 11, 14, 11}; //the value is a number of milliseconds

const unsigned long speaker[198] = {14, 30, 19, 31, 2, 11, 14, 3, 11, 14, 30, 19, 5, 19, 31, 21, 14, 11, 10, 19, 14, 21, 31, 11, 2, 19, 14, 8, 19, 11, 7, 4, 10, 11, 2, 14, 3, 10, 19, 5, 4, 19, 7, 8, 7, 19, 14, 8, 11, 19, 14, 30, 21, 19, 3, 4, 11, 21, 9, 14, 19, 11, 30, 11, 2, 4, 21, 19, 30, 11, 30, 14, 5, 31, 8, 14, 9, 21, 3, 9, 10, 11, 19, 2, 14, 19, 9, 19, 14, 2, 3, 14, 5, 2, 7, 14, 19, 14, 2, 19, 11, 30, 7, 3, 10, 19, 14, 9, 11, 19, 14, 19, 14, 5, 14, 19, 11, 19, 7, 19, 14, 19, 14, 3, 11, 30, 31, 7, 19, 11, 19, 2, 14, 19, 11, 14, 30, 8, 14, 11, 14, 11, 2, 11, 14, 5, 19, 14, 11, 30, 19, 14, 8, 9, 14, 19, 10, 19, 14, 8, 2, 19, 9, 14, 11, 19, 9, 2, 19, 2, 14, 11, 8, 14, 2, 19, 21, 11, 19, 4, 30, 9, 14, 11, 7, 19, 11, 9, 19, 30, 19, 11, 14, 19, 14, 11, 14, 11}; //the value is a number of milliseconds

// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver: #define dirPin 12 //dir 12 #define stepPin 20 //pul + 11 #define audioPinOut 45 //#define voicePin 10 // power for mp3 reader #define motorInterfaceType 1 // /1 /2 /3 /4 /5 /6 /7 /8 /9 /10/11 /12 /13 /14 /15 /16 /17 /18

int enablePin[19] = {30, 31, 2, 3, 4, 5, 21, 7, 8, 9, 10, 11, 19, 14, 15, 16, 17, 18};

// formule excel : =(SI(A8=1;30;SI(A8=2;31;SI(A8=3;2;SI(A8=4;3;SI(A8=5;4;SI(A8=6;5;SI(A8=7;6;SI(A8=8;7;SI(A8=9;8;SI(A8=10;9;SI(A8=11;10;SI(A8=12;11;SI(A8=13;19;SI(A8=14;14;SI(A8=15;15;SI(A8=16;16;SI(A8=17;17;SI(A8=18;18;SI))))))))))))))))))) //int voicePin[20] = {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43};

float motorTime = 3562 ; long initial_homing =0;

// Create a new instance of the AccelStepper class: AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin); int initialOpenPos = -350; int openPos = -350; int closePos = 0;

// formule excel : =(SI(A8=1;30;SI(A8=2;31;SI(A8=3;2;SI(A8=4;3;SI(A8=5;4;SI(A8=6;5;SI(A8=7;6;SI(A8=8;7;SI(A8=9;8;SI(A8=10;9;SI(A8=11;10;SI(A8=12;11;SI(A8=13;19;SI(A8=14;14;SI(A8=15;15;SI(A8=16;16;SI(A8=17;17;SI(A8=18;18;SI))))))))))))))))))) //int voicePin[20] = {24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43};

float motorTime = 3562 ; long initial_homing =0;

// Create a new instance of the AccelStepper class: AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin); int initialOpenPos = -350; int openPos = -350; int closePos = 0;

int vitesseDeTest = 1000; int vitesseAction = 500;

void setup() { Serial.begin(115200); Serial.println("truc");

// Set the maximum speed and acceleration: stepper.setMaxSpeed(vitesseDeTest); // max 50 000 pour petit stepper arduino starter stepper.setAcceleration(100); // max 20 000

// on initalise tout les output pour les enable et les voix for(int i = 0; i < 21; i++){ // tester la valeur max ? 21? pinMode(enablePin[i], OUTPUT); //pinMode(voicePin[i], OUTPUT); }
pinMode(audioPinOut, OUTPUT); digitalWrite(audioPinOut, LOW);

// On test l'ouverture des cartons for(int a = 0; a < 21; a++){ digitalWrite(enablePin[a], LOW); }
Serial.println("start"); stepper.moveTo(openPos); //*230000 max 250000 100000 while ((stepper.distanceToGo() != 0))
{ stepper.run(); }
Serial.println("finishhhh"); delay(1000); stepper.moveTo(closePos+150); while ((stepper.distanceToGo() != 0)) { stepper.run(); }
delay(1000); stepper.setCurrentPosition(0);
for(int b = 0; b < 21; b++){ digitalWrite(enablePin[b], HIGH); } // digitalWrite(enablePin[10], HIGH); // digitalWrite(enablePin[14], HIGH); // // digitalWrite(enablePin[13], HIGH);

// // On test les voix // for(int a = 0; a < 21; a++){ // digitalWrite(voicePin[a], HIGH); // delay(500); // digitalWrite(voicePin[a], LOW); // }

stepper.setMaxSpeed(vitesseAction); delay(2000); digitalWrite(audioPinOut, HIGH); delay(1850); }

void loop(){ // ouverture premier carton motorTime = motorTime*2; for(int itera = 0; itera <= 198; itera ++){ digitalWrite(speaker[itera], LOW); //// carton 1 if(period[itera] < motorTime){ float calcul = period[itera]; float divid = motorTime/period[itera]; Serial.print("divid ="); Serial.println(divid); openPos = openPos/divid; Serial.print("openPos ="); Serial.println(openPos); } else{ openPos=initialOpenPos; } stepper.moveTo(openPos); // ouverture du carton 13 while ((stepper.distanceToGo() != 0)) { stepper.run(); } if(period[itera]- (motorTime) <= 0){ delay(0); } else{ delay(period[itera]- (motorTime)); // on attend } // delay(100); stepper.moveTo(closePos); // fermeture du carton 13 while ((stepper.distanceToGo() != 0)) { stepper.run(); } digitalWrite(speaker[itera], HIGH); //// carton 1 } reboot(); }

void reboot() { wdt_enable(WDTO_15MS); // activer le watchdog while (1) {}; // et attendre ... }

Élie Bolard