Bonjours,
J'ai dans l’ambition de commandé les 8 volets roulant de ma maison. J'ai commandes un arduino Mega, un modul DS1302RTC et 2 cartes relais: une de 16V et une de 4V. Mais mon problème est que je début avec l'arduino et sont langage. le câblage me pose pas de problème, c'est plus la programmation de l'Arduino. Je suis pas sur de bien géré le temps, ma commande d'ouverture et fermeture. pouvais vous m'aidé et m'expliqué mes erreurs.
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | #define VOLE_1_F 2 #define VOLE_1_O 3 #define VOLE_2_F 4 #define VOLE_2_O 5 #define VOLE_3_F 6 #define VOLE_3_O 7 #define VOLE_4_F 8 #define VOLE_4_O 9 #define VOLE_5_F 10 #define VOLE_5_O 11 #define VOLE_6_F 12 #define VOLE_6_O 13 #define VOLE_7_F 14 #define VOLE_7_O 15 #define VOLE_8_F 16 #define VOLE_8_O 17 #define PH_1 18 #define PH_2 19 #define PH_3 20 #include <DS1302RTC.h> #include <Streaming.h> #include <Time.h> // Connection des broche du DS1302RTC: CE, IO,CLK DS1302RTC RTC(A0, A1, A2); int date_heure = hour(); // variable date_heure contient l'heure actuelle int date_minute = minute(); // variable date_minute contient la minute actuelle int date_seconde = second(); // variable date_seconde contient la minute actuelle void setup() { { // on initialise les sorties RELAIS // Carte 16V commandede mes 8 volet pinMode(VOLE_1_F, OUTPUT); pinMode(VOLE_1_O, OUTPUT); pinMode(VOLE_2_F, OUTPUT); pinMode(VOLE_2_O, OUTPUT); pinMode(VOLE_3_F, OUTPUT); pinMode(VOLE_3_O, OUTPUT); pinMode(VOLE_4_F, OUTPUT); pinMode(VOLE_4_O, OUTPUT); pinMode(VOLE_5_F, OUTPUT); pinMode(VOLE_5_O, OUTPUT); pinMode(VOLE_6_F, OUTPUT); pinMode(VOLE_6_O, OUTPUT); pinMode(VOLE_7_F, OUTPUT); pinMode(VOLE_7_O, OUTPUT); pinMode(VOLE_8_F, OUTPUT); pinMode(VOLE_8_O, OUTPUT); // Carte 4V commande de mes 3 phase pinMode(PH_1, OUTPUT); pinMode(PH_2, OUTPUT); pinMode(PH_3, OUTPUT); //On place tous les relais au repos pour le bon fonctionnement de mon installation digitalWrite(VOLE_1_F, HIGH); digitalWrite(VOLE_1_O, HIGH); digitalWrite(VOLE_2_F, HIGH); digitalWrite(VOLE_2_O, HIGH); digitalWrite(VOLE_3_F, HIGH); digitalWrite(VOLE_3_O, HIGH); digitalWrite(VOLE_4_F, HIGH); digitalWrite(VOLE_4_O, HIGH); digitalWrite(VOLE_5_F, HIGH); digitalWrite(VOLE_5_O, HIGH); digitalWrite(VOLE_6_F, HIGH); digitalWrite(VOLE_6_O, HIGH); digitalWrite(VOLE_7_F, HIGH); digitalWrite(VOLE_7_O, HIGH); digitalWrite(VOLE_8_F, HIGH); digitalWrite(VOLE_8_O, HIGH); digitalWrite(PH_1, HIGH); digitalWrite(PH_2, HIGH); digitalWrite(PH_3, HIGH); } { Serial.begin(115200); // Activate RTC module Serial << F("RTC module activated"); Serial << endl; delay(500); if (RTC.haltRTC()) { Serial << F("The DS1302 is stopped. Please set time"); Serial << F("to initialize the time and begin running."); Serial << endl; } if (!RTC.writeEN()) { Serial << F("The DS1302 is write protected. This normal."); Serial << endl; } delay(5000); //setSyncProvider() causes the Time library to synchronize with the //external RTC by calling RTC.get() every five minutes by default. setSyncProvider(RTC.get); Serial << F("RTC Sync"); if (timeStatus() == timeSet) Serial << F(" Ok!"); else Serial << F(" FAIL!"); Serial << endl; } } void loop() { // Ouverture des volets a 8h30 if (date_heure == 8 && date_minute == 30 && date_seconde == 00) // Si il est 8h30. { // activé les relais montée digitalWrite(PH_1, LOW); digitalWrite(PH_2, LOW); digitalWrite(PH_3, LOW); digitalWrite(VOLE_1_O, LOW); digitalWrite(VOLE_2_O, LOW); digitalWrite(VOLE_3_O, LOW); digitalWrite(VOLE_4_O, LOW); digitalWrite(VOLE_5_O, LOW); digitalWrite(VOLE_6_O, LOW); digitalWrite(VOLE_7_O, LOW); digitalWrite(VOLE_8_O, LOW); // tempos de 2 minutes 30s delay(150000); // Remise en condition repos des relais ouvertures digitalWrite(PH_1, HIGH); digitalWrite(PH_2, HIGH); digitalWrite(PH_3, HIGH); digitalWrite(VOLE_1_O, HIGH); digitalWrite(VOLE_2_O, HIGH); digitalWrite(VOLE_3_O, HIGH); digitalWrite(VOLE_4_O, HIGH); digitalWrite(VOLE_5_O, HIGH); digitalWrite(VOLE_6_O, HIGH); digitalWrite(VOLE_7_O, HIGH); digitalWrite(VOLE_8_O, HIGH); } // fermetures des volets a 20h30 if (date_heure == 20 && date_minute == 30 && date_seconde == 00) // Si il est 20h30. { digitalWrite(PH_1, LOW); digitalWrite(PH_2, LOW); digitalWrite(PH_3, LOW); digitalWrite(VOLE_1_F, LOW); digitalWrite(VOLE_2_F, LOW); digitalWrite(VOLE_3_F, LOW); digitalWrite(VOLE_4_F, LOW); digitalWrite(VOLE_5_F, LOW); digitalWrite(VOLE_6_F, LOW); digitalWrite(VOLE_7_F, LOW); digitalWrite(VOLE_8_F, LOW); // tempos de 2 minutes 30s delay(150000); // Remise en condition repos des relais fermetures digitalWrite(PH_1, HIGH); digitalWrite(PH_2, HIGH); digitalWrite(PH_3, HIGH); digitalWrite(VOLE_1_F, HIGH); digitalWrite(VOLE_2_F, HIGH); digitalWrite(VOLE_3_F, HIGH); digitalWrite(VOLE_4_F, HIGH); digitalWrite(VOLE_5_F, HIGH); digitalWrite(VOLE_6_F, HIGH); digitalWrite(VOLE_7_F, HIGH); digitalWrite(VOLE_8_F, HIGH); } { static time_t tLast; time_t t; tmElements_t tm; //check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s if (Serial.available() >= 12) { //note that the tmElements_t Year member is an offset from 1970, //but the RTC wants the last two digits of the calendar year. //use the convenience macros from Time.h to do the conversions. int y = Serial.parseInt(); if (y >= 100 && y < 1000) Serial << F("Error: Year must be two digits or four digits!") << endl; else { if (y >= 1000) tm.Year = CalendarYrToTm(y); else //(y < 100) tm.Year = y2kYearToTm(y); tm.Month = Serial.parseInt(); tm.Day = Serial.parseInt(); tm.Hour = Serial.parseInt(); tm.Minute = Serial.parseInt(); tm.Second = Serial.parseInt(); t = makeTime(tm); //use the time_t value to ensure correct weekday is set if(RTC.set(t) == 0) { // Success setTime(t); Serial << F("RTC set to: "); printDateTime(t); Serial << endl; } else Serial << F("RTC set failed!") << endl; //dump any extraneous input while (Serial.available() > 0) Serial.read(); } } t = now(); if (t != tLast) { tLast = t; printDateTime(t); Serial << endl; } } //print date and time to Serial void printDateTime(time_t t) { printDate(t); Serial << ' '; printTime(t); } //print time to Serial void printTime(time_t t) { printI00(hour(t), ':'); printI00(minute(t), ':'); printI00(second(t), ' '); } //print date to Serial void printDate(time_t t) { printI00(day(t), 0); Serial << monthShortStr(month(t)) << _DEC(year(t)); } //Print an integer in "00" format (with leading zero), //followed by a delimiter character to Serial. //Input value assumed to be between 0 and 99. void printI00(int val, char delim) { if (val < 10) Serial << '0'; Serial << _DEC(val); if (delim > 0) Serial << delim; return; } } |
Merci d'avance de votre aides
+0
-0