Advertisement
nikolas77

Programmateur horaire

Nov 3rd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_GFX.h>
  2. #include <MCUFRIEND_kbv.h>
  3. MCUFRIEND_kbv tft;
  4.  
  5. #include "RTClib.h"
  6.  
  7. RTC_PCF8523 rtc;
  8.  
  9. #define BLACK           0x0000                                                                                                  // Variables contenant la valeur sur 16 bits des couleurs
  10. #define WHITE           0xFFFF
  11.  
  12. uint16_t g_identifier;                                                                                                          // Identifiant de l'écran TFT
  13. uint8_t OrientationTFT = 1;
  14.  
  15. const int Broche_Relais1 = 37;     //neons UVB
  16. const int Broche_Relais2 = 35;     //lampe chauffante
  17.  
  18. int Hrs = 0;
  19. int LastHrs = 0;
  20.  
  21. void setup(){
  22.    
  23.     pinMode(Broche_Relais1, OUTPUT);
  24.     pinMode(Broche_Relais2, OUTPUT);
  25.    
  26.     digitalWrite(Broche_Relais1, HIGH);
  27.     digitalWrite(Broche_Relais2, HIGH);
  28.    
  29.     tft.begin(9600);                                                                                                              // Démarre la communication avec l'écran TFT
  30.     tft.reset();                                                                                                                  // Initialise l'écran TFT
  31.     g_identifier = tft.readID();                                                                                                  // Lecture de l'identifiant de l'écran TFT
  32.     tft.begin(g_identifier);                                                                                                      // Démarre la librairie de l'écran TFT
  33.  
  34.     tft.fillScreen(BLACK);                                                                                                        // Initialise la couleur du fond d'écran
  35.     tft.setRotation(OrientationTFT);
  36.    
  37. if (! rtc.begin()) {
  38.   }
  39.   if (! rtc.initialized()) {
  40.   }
  41.  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  42. }    
  43. void loop(){
  44.    
  45.      gestionHorloge();
  46. }
  47. void  gestionHorloge(){                                //partie horloge
  48.  
  49.          DateTime now = rtc.now();
  50.  
  51.      tft.setTextColor(WHITE,BLACK);                        
  52.      tft.setCursor(100, 5);
  53.      tft.setTextSize(3);
  54.    if (now.hour() < 10) {tft.print('0');}
  55.      tft.print(now.hour(), DEC);
  56.      tft.print(':');
  57.    if (now.minute() < 10) {tft.print('0');}
  58.      tft.print(now.minute(), DEC);
  59.      tft.print(':');
  60.    if (now.second() < 10) {tft.print('0');}
  61.      tft.print(now.second(), DEC);
  62.      
  63. if(now.hour()==8&&now.minute()==00&&now.second()<=1){        //programmation eclairages
  64.  
  65.      digitalWrite(Broche_Relais1, HIGH);
  66.      digitalWrite(Broche_Relais2, HIGH);  
  67. }
  68. else if(now.hour()==22&&now.minute()==00&&now.second()<=1){
  69.  
  70.      digitalWrite(Broche_Relais1, LOW);
  71.      digitalWrite(Broche_Relais2, LOW);  
  72. }  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement