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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
| #include <Time.h>
#include <Arduino.h>
#include <Wire.h>
#include <DS1307.h>
#include <OneWire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define sclk 13
#define mosi 11
#define cs 10
#define dc 9
#define rst 8
#define DS18B20 0x28 // Adresse 1-Wire du DS18B20
#define BROCHE_ONEWIRE 7 // Broche utilisée pour le bus 1-Wire
OneWire ds(BROCHE_ONEWIRE); // Création de l'objet OneWire ds
int chauffage = 0;
int brassage = 1;
int neon_1 = 2;
int neon_2 = 3;
int led_nuit = 4;
int pwm = 5;
int chauffage_on = 27; //allume chauffage à cette température
int chauffage_off = 27; //éteint le chauffage à cette température
int led_nuit_on = 2000; //allume les led nocturne à cette heure (en temps_perso)
int led_nuit_off = 2300; //éteint les led nocturne à cette heure (en temps_perso)
int brassage_on = 1221; //allume pompe brassage à cette heure (en temps_perso)
int brassage_off = 1225; //éteint pompe brassage à cette heure (en temps_perso)
int neon_1_on = 1222; //allume le néon 1 à cette heure (en temps_perso)
int neon_1_off = 1226; //éteint les led nocturne à cette heure (en temps_perso)
int neon_2_on = 1223; //allume le néon 2 à cette heure (en temps_perso)
int neon_2_off = 1227;
int minut;
int heure;
int seconde;
int jour;
int date;
int mois;
int annee;
int temps_perso;
int BP1=16; //interrupteur Day_light
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
// Fonction récupérant la température depuis le DS18B20 ****************************************************************
// Retourne true si tout va bien, ou false en cas d'erreur *************************************************************
boolean getTemperature(float *temp){
byte data[9], addr[8];
// data : Données lues depuis le scratchpad ****************************************************************************
// addr : adresse du module 1-Wire détecté *****************************************************************************
if (!ds.search(addr)) { // Recherche un module 1-Wire
ds.reset_search(); // Réinitialise la recherche de module
return false; // Retourne une erreur
}
if (OneWire::crc8(addr, 7) != addr[7]) // Vérifie que l'adresse a été correctement reçue
return false; // Si le message est corrompu on retourne une erreur
if (addr[0] != DS18B20) // Vérifie qu'il s'agit bien d'un DS18B20
return false; // Si ce n'est pas le cas on retourne une erreur
ds.reset(); // On reset le bus 1-Wire
ds.select(addr); // On sélectionne le DS18B20
ds.write(0x44, 1); // On lance une prise de mesure de température
delay(1); // Et on attend la fin de la mesure
ds.reset(); // On reset le bus 1-Wire
ds.select(addr); // On sélectionne le DS18B20
ds.write(0xBE); // On envoie une demande de lecture du scratchpad
for (byte i = 0; i < 9; i++) // On lit le scratchpad
data[i] = ds.read(); // Et on stock les octets reçus
// Calcul de la température en degré Celsius ***************************************************************************
*temp = ((data[1] << 8) | data[0]) * 0.0625;
// Pas d'erreur ********************************************************************************************************
return true;
}
void setup() {
/* RTC.stop();
RTC.set(DS1307_SEC,00); //réglage secondes
RTC.set(DS1307_MIN,43); //réglage minutes
RTC.set(DS1307_HR,20); //réglage heures
RTC.set(DS1307_DOW,3); //réglage jour de la semaine
RTC.set(DS1307_DATE,1); //réglage date
RTC.set(DS1307_MTH,6); //réglage mois
RTC.set(DS1307_YR,16); //réglage année
RTC.start();
*/
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_BLACK);
pinMode(chauffage, OUTPUT); // digital pin pour chauffage en sortie
pinMode(brassage, OUTPUT); // digital pin pour pompe en sortie
pinMode(neon_1, OUTPUT); // digital pin pour neon 1 en sortie
pinMode(neon_2, OUTPUT); // digital pin pour neon 2 en sortie
pinMode(led_nuit, OUTPUT); // digital pin pour moon light en sortie
pinMode(BP1, INPUT); // met la broche en entree
digitalWrite(BP1, HIGH) ; // activation du pullup de la broche en entrée
}
void loop(){
//Récupérer l'heure du DS1307*******************************************************************************************
heure = RTC.get(DS1307_HR,true);
minut = RTC.get(DS1307_MIN,false);
seconde = RTC.get(DS1307_SEC,false);
jour = RTC.get(DS1307_DOW,false);
date = RTC.get(DS1307_DATE,false);
mois = RTC.get(DS1307_MTH,false);
annee = RTC.get(DS1307_YR,false);
temps_perso = (heure * 100) + minut; //creation temps_perso
//Affichage trait separation********************************************************************************************
tft.drawLine(0,20,128,20,ST7735_MAGENTA);
tft.drawLine(0,40,128,40,ST7735_MAGENTA);
tft.drawLine(0,60,128,60,ST7735_MAGENTA);
tft.drawLine(64,60,64,80,ST7735_MAGENTA);
tft.drawLine(0,80,128,80,ST7735_MAGENTA);
tft.drawLine(0,100,128,100,ST7735_MAGENTA);
tft.drawLine(0,120,128,120,ST7735_MAGENTA);
tft.drawLine(64,100,64,160,ST7735_MAGENTA);
tft.drawLine(0,140,128,140,ST7735_MAGENTA);
//Affichage de la data**************************************************************************************************
tft.setTextColor(ST7735_WHITE);
tft.setCursor(18,5);
switch (RTC.get(DS1307_DOW,false)) { // affiche le jours
case 1:
tft.print("Lun");
break;
case 2:
tft.print("Mar");
break;
case 3:
tft.print("Mer");
break;
case 4:
tft.print("Jeu");
break;
case 5:
tft.print("Ven");
break;
case 6:
tft.print("Sam");
break;
case 7:
tft.print("Dim");
break; }
tft.print(" ");
tft.print(RTC.get(DS1307_DATE,false)); // affiche la date
tft.print(" ");
switch (RTC.get(DS1307_MTH,false)) { // affiche le moi
case 1:
tft.print("janvier");
break;
case 2:
tft.print("fevrier");
break;
case 3:
tft.print("mars");
break;
case 4:
tft.print("avril");
break;
case 5:
tft.print("mai");
break;
case 6:
tft.print("juin");
break;
case 7:
tft.print("juillet");
break;
case 8:
tft.print("aout");
break;
case 9:
tft.print("septembre");
break;
case 10:
tft.print("octobre");
break;
case 11:
tft.print("novembre");
break;
case 12:
tft.print("decembre");
break; }
tft.print(" ");
tft.print("2016");
//Affichage heure******************************************************************************************
tft.setCursor(20,25);
tft.fillRect(60,25,50,10,ST7735_BLACK); // efface les secondes
tft.print("Heure:"); // affiche ligne heure
tft.setCursor(60,25);
tft.print(RTC.get(DS1307_HR,true)); // affiche le heures
tft.print(":");
if ((RTC.get(DS1307_MIN,false)) <= 9) // ajoute un 0 devant si minute égal ou inférieur a 9
{
tft.print("0");
}
if (seconde == 00) { // effface les minute
tft.fillRect(0,0,85,20,ST7735_BLACK);
}
tft.print(RTC.get(DS1307_MIN,false)); // affiche les minutes
tft.print(":");
if ((RTC.get(DS1307_SEC,false)) <= 9) // ajoute un 0 devant si seconde égal ou inférieur a 9
{
tft.print('0');
}
tft.print(RTC.get(DS1307_SEC,false)); // affiche le secondes
//Affichage température************************************************************************************
float temp;
// Lit la température ambiante à ~1Hz
if(getTemperature(&temp)) {
tft.setCursor(26,45);
tft.print("Temp:");
tft.fillRect(59,45,30,10,ST7735_BLACK); // efface temp reel
tft.setCursor(59,45);
tft.print(temp);
tft.setCursor(95,45);
tft.print("C");
tft.setCursor(5, 65);
tft.print("Min: ");
tft.setCursor(68, 65);
tft.print("Max: ");
tft.setCursor(30, 65); // affiche temperature mini
tft.setCursor(95, 65); // affiche temperature maxi
}
//Controles des sorties ***************************************************************************************
//****************Chauffage
if((temp > chauffage_on)) {
digitalWrite(chauffage, HIGH);
}
else if (temp >= chauffage_off)
{
digitalWrite(chauffage, LOW);
}
//****************Brassage
if(temps_perso < brassage_on || temps_perso > brassage_off) {
digitalWrite(brassage, HIGH);
}
else {
digitalWrite(brassage, LOW);
}
//****************Neon 1
if(temps_perso < neon_1_on || temps_perso > neon_1_off) {
digitalWrite(neon_1, HIGH);
}
else {
digitalWrite(neon_1, LOW);
}
//****************Neon 2
if(temps_perso < neon_2_on || temps_perso > neon_2_off) {
digitalWrite(neon_2, HIGH);
}
else {
digitalWrite(neon_2, LOW);
}
//****************Day Lights
if (heure == 15) { // entre 15:00 et 15:59:59
analogWrite (pwm, (1 << map (minute() * 60 + second(), 0, 3600, 0, 10)) -1); // allumage progressif exponentiel
// analogWrite (pwm, map (minute() * 60 + second(), 0, 3600, 0, 1024)); // allumage progressif linéaire
}
else if (heure == 20) { // entre 20:00 et 20:59:59
analogWrite (pwm, (1 << map (minute() * 60 + second(), 0, 3600, 10, 0)) -1); // extinction progressif exponentiel
// analogWrite (pwm, map (minute() * 60 + second(), 0, 3600, 1024, 0)); // extinction progressif linéaire
}
else if ((heure > 15 ) && (heure < 20)) {
analogWrite(pwm, 255);
}
else if (((heure > 0 && heure < 15)) && (digitalRead(BP1)==LOW)) {
analogWrite(pwm, 255);
}
else if (((heure > 20 && heure < 24)) && (digitalRead(BP1)==LOW)) {
analogWrite(pwm, 255);
}
else if ((heure == 0) && (digitalRead(BP1)==LOW)) {
analogWrite(pwm, 255);
}
else if (((heure > 0 && heure < 15)) && (digitalRead(BP1)==HIGH)) {
analogWrite(pwm, 0);
}
else if (((heure > 20 && heure < 24)) && (digitalRead(BP1)==HIGH)) {
analogWrite(pwm, 0);
}
else if ((heure == 0) && (digitalRead(BP1)==HIGH)) {
analogWrite(pwm, 0);
}
//****************Moon Lights
if(led_nuit_on > temps_perso || led_nuit_off < temps_perso){
digitalWrite(led_nuit, LOW);
}
else{
digitalWrite(led_nuit, HIGH);
}
//Affichage chauffage allumé
if(digitalRead(chauffage) == LOW)
{
tft.fillRect(00,141,64,19,ST7735_GREEN);
tft.setCursor(5,147);
tft.setTextColor(ST7735_BLACK);
tft.print("Chauffage");
}
else
{
tft.fillRect(00,141,64,19,ST7735_RED);
tft.setCursor(5,147);
tft.setTextColor(ST7735_WHITE);
tft.print("Chauffage");
}
//Affichage brassage allumé
if(digitalRead(brassage) == LOW)
{
tft.fillRect(65,141,65,19,ST7735_GREEN);
tft.setCursor(74,147);
tft.setTextColor(ST7735_BLACK);
tft.print("Brassage");
}
else
{
tft.fillRect(65,141,65,19,ST7735_RED);
tft.setCursor(74,147);
tft.setTextColor(ST7735_WHITE);
tft.print("Brassage");
}
//Affichage neon 1 allumé
if(digitalRead(neon_1) == LOW)
{
tft.fillRect(00,121,64,19,ST7735_GREEN);
tft.setCursor(15,127);
tft.setTextColor(ST7735_BLACK);
tft.print("Neon 1");
}
else
{
tft.fillRect(00,121,64,19,ST7735_RED);
tft.setCursor(15,127);
tft.setTextColor(ST7735_WHITE);
tft.print("Neon 1");
}
//Affichage neon 2 allumé
if(digitalRead(neon_2) == LOW)
{
tft.fillRect(65,121,65,19,ST7735_GREEN);
tft.setCursor(79,127);
tft.setTextColor(ST7735_BLACK);
tft.print("Neon 2");
}
else
{
tft.fillRect(65,121,65,19,ST7735_RED);
tft.setCursor(79,127);
tft.setTextColor(ST7735_WHITE);
tft.print("Neon 2");
}
//Affichage eclairage nocturne allumé
if(digitalRead(led_nuit) == HIGH)
{
tft.fillRect(00,101,64,19,ST7735_GREEN);
tft.setCursor(8,105);
tft.setTextColor(ST7735_BLACK);
tft.print("Led nuit");
}
else
{
tft.fillRect(00,101,64,19,ST7735_RED);
tft.setCursor(8,105);
tft.setTextColor(ST7735_WHITE);
tft.print("Led nuit");
}
// affichage niveau pwm
tft.setCursor(70,105);
tft.print("PWM");
} |
Partager