#include double ha; double az; String lS, mS, cS; int amplitudeHoraire = 5; int minH = 0; int maxH = 0; int minM = 0; int maxM = 0; int minAz = 0; int maxAz = 0; // PINS #define RTC_CLOCK 6 #define RTC_DATA 7 #define RTC_RESET 8 #define PWMA 5 //Right side #define PWMB 4 //Left side #define DA 0 //Right reverse #define DB 2 //Left reverse // Load the virtuabotixRTC library #include "virtuabotixRTC.h" // Determine the pins connected to the module // myRTC (clock, data, RST) virtuabotixRTC myRTC (RTC_CLOCK, RTC_DATA, RTC_RESET); int theorique_position = -1; String date = ""; String heure = ""; const int LONGUEUR_UTILE = 40; const int LATITUDE = 47.726682; const int LONGITUDE = -2.131774; const int ANGLE_MINI = 5; const int ANGLE_ROTATION = 90; void setup() { // initialize digital pin LED_BUILTIN as an output. Serial.begin(9600); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); stop(); // After to set the entire information, comment the following line // (seconds, minutes, hours, day of week, day of month, month, year) // myRTC.setDS1302Time (0, 24, 20, 5, 19, 7, 2024); } void loop() { // Reads the information from the CI myRTC.updateTime(); printTime(); // Serial.println("NEW-YORK, Manhattan ; position du soleil le 12/02/2017 a 09:32:18"); // posSoleil("28/05/2021 14:00:18", -5, 40.76, -73.984, &ha, &az); // Manhattan le 12/02/2017 // Serial.println(" hauteur : " + String(ha, 7) + " azimut : " + String(az, 7)); // Serial.println(); //Serial.println("Glenac ; position du soleil"); //posSoleil("28/05/2021 14:00:00", 0, LATITUDE, LONGITUDE, &ha, &az); // Tour Eiffel le 12/02/2017 //Serial.println(" hauteur : " + String(ha, 7) + " azimut : " + String(az, 7)); // il faut que l'Azimut soit supérieur à 0 posSoleil( myRTC.year, myRTC.month, myRTC.dayofmonth, myRTC.hours, myRTC.minutes, myRTC.seconds, /*décalage GMT*/ 2, LATITUDE, LONGITUDE, &ha, &az); // Même calcul que ci-dessus mais avec date et heure sous form d'entiers Serial.println(" hauteur : " + String(ha, 7) + " azimut : " + String(az, 7)); //Serial.println("Glenac; lever, zenith et coucher : 19 m"); //lmvSoleil("28/05/2021", 2, 0, LATITUDE, LONGITUDE, &lS, &mS, &cS, 19); lmvSoleil( myRTC.year, myRTC.month, myRTC.dayofmonth, /*décalage GMT*/ 2, 0, LATITUDE, LONGITUDE, &lS, &mS, &cS, 19); int hlS = lS.substring(0, 2).toInt(); int mnlS = lS.substring(3, 5).toInt(); int hcS = cS.substring(0, 2).toInt(); int mncS = cS.substring(3, 5).toInt(); if (theorique_position == -1) { int min_angle = 180 - ANGLE_ROTATION / 2; int max_angle = 180 + ANGLE_ROTATION / 2; for (int h = hlS; h <= hcS; h++) { for (int m = 0; m <= 50; m+=10) { // double ha2; // double az2; posSoleil( /*2021, 12, 21, */ myRTC.year, myRTC.month, myRTC.dayofmonth, h, m, 0, /*décalage GMT*/ 2, LATITUDE, LONGITUDE, &ha, &az); // Même calcul que ci-dessus mais avec date et heure sous form d'entiers Serial.println(String(h) + ":" + String(m) + " ==> hauteur : " + String(ha, 2) + " azimut : " + String(az, 2)); // if (ha2 > ANGLE_MINI && minH == 0) { // minH = h; // minM = m; // minAz = az2; // } // if (ha2 > ANGLE_MINI) { // maxH = h; // maxM = m; // maxAz = az2; // } if (az > min_angle && minH == 0) { minH = h; minM = m; minAz = az; } if (az < max_angle) { maxH = h; maxM = m; maxAz = az; } } } amplitudeHoraire = (maxH * 60 + maxM) - (minH * 60 + minM); Serial.println("amplitudeHoraire : " + String(minH) + ":" + String(minM) + " " + String(maxH) + ":" + String(maxM) + " " + String(minAz) + " " + String(maxAz) + " amplitude=" + amplitudeHoraire); for (int h = hlS; h <= hcS; h++) { for (int m = 0; m <= 50; m+=10) { posSoleil( myRTC.year, myRTC.month, myRTC.dayofmonth, h, m, 0, /*décalage GMT*/ 2, LATITUDE, LONGITUDE, &ha, &az); // Même calcul que ci-dessus mais avec date et heure sous form d'entiers calculatePosition(h,m); } } } Serial.println(" lever : " + lS + " zenith : " + mS + " coucher : " + cS); // Serial.println("Glenac ; lever, zenith et coucher en haut de la Tour Eiffel : 350 m"); // lmvSoleil("12/02/2017", 0, 0, LATITUDE, LONGITUDE, &lS, &mS, &cS, 350); // Serial.println(" lever : " + lS + " zenith : " + mS + " coucher : " + cS); if (theorique_position == -1) { retourEnZero(); } Serial.println("Calcul position pour heure " + heure); int h = heure.substring(0, 2).toInt(); int mn = heure.substring(3, 5).toInt(); int positionTogo = calculatePosition(h,mn); gotoPosition(positionTogo); delay(10000); } void printTime() { // Print the details in serial monitor Serial.print ("Data "); // Call the routine that prints the day of the week jourSemaine (myRTC.dayofweek); Serial.print (", "); date = (myRTC.dayofmonth < 10 ? "0" : "") + String(myRTC.dayofmonth) + "/" + (myRTC.month < 10 ? "0" : "") + String(myRTC.month) + "/" + String(myRTC.year); Serial.print (date); heure = (myRTC.hours < 10 ? "0" : "") + String(myRTC.hours) + ":" + (myRTC.minutes < 10 ? "0" : "") + String(myRTC.minutes) + ":" + (myRTC.seconds < 10 ? "0" : "") + String(myRTC.seconds); Serial.println(" Time " + heure); // Adds a 0 if the time value is <10 } void stop() { Serial.println("stop"); digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) digitalWrite(3, LOW); digitalWrite(4, LOW); delay(200); Serial.println("stop fin"); } void avance() { Serial.println("avance"); digitalWrite(4, HIGH); delay(200); digitalWrite(3, LOW); digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) Serial.println("avance fin"); } void recule() { Serial.println("recule"); digitalWrite(4, LOW); delay(200); digitalWrite(3, HIGH); digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level) Serial.println("recule fin"); } void retourEnZero() { Serial.println("retour en zero"); stop(); recule(); for (int i = 0; i < LONGUEUR_UTILE + 5; i++) { delay(1000); //LONGUEUR_UTILE * 1200); Serial.print("."); } stop(); Serial.println("Fin retour en zero"); } void gotoPosition(int positionTogo) { Serial.println("gotoPosition " + String(positionTogo)); if (theorique_position != positionTogo) { if (positionTogo > theorique_position) { avance(); Serial.println("delay " + String(positionTogo - theorique_position)); for (int i = 0; i < (positionTogo - theorique_position); i++) { delay(1000); Serial.print("."); } //delay((positionTogo - theorique_position) * 1000); } else { recule(); Serial.println("delay " + String(theorique_position - positionTogo)); for (int i = 0; i < (theorique_position - positionTogo); i++) { delay(1000); Serial.print("."); } // delay((theorique_position - positionTogo) * 1000); } Serial.println("avant stop"); stop(); Serial.println("apres stop"); } theorique_position = positionTogo; if (theorique_position < -1) { theorique_position = -1; } Serial.println("gotoPosition fin"); } int calculatePosition(int h, int mn) { int position = 0; if ( ha > ANGLE_MINI) { if (az <= minAz) { position = 0; } if (az > minAz && az <= maxAz) { int hS = minH; //lS.substring(0, 2).toInt(); int mnS = lS.substring(3, 5).toInt(); int minutes = h * 60 + mn - minH * 60 - minM; position = min(LONGUEUR_UTILE, (LONGUEUR_UTILE * minutes / amplitudeHoraire)); } if (az > maxAz) { position = LONGUEUR_UTILE; } } else { position = LONGUEUR_UTILE / 2; } Serial.println("Calcul position " + String(h) + " " + String(mn) + " " + String(position)); return position; } void jourSemaine (int day) { switch (day) { case 1: Serial.print("Lundi"); break; case 2: Serial.print("Mardi"); break; case 3: Serial.print("Mercredi"); break; case 4: Serial.print("Jeudi"); break; case 5: Serial.print("Vendredi"); break; case 6: Serial.print("Samedi"); break; case 7: Serial.print("Dimanche"); break; } }