Advertisement
deaphroat

weeduina

Oct 15th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 19.35 KB | None | 0 0
  1. #include "DHT.h"
  2. #include <UTFT.h>
  3. #include <UTouch.h>
  4. #include <UTFT_Buttons.h>
  5. #include <avr/pgmspace.h>
  6. #include <Wire.h>
  7. #include <RTClib.h>
  8. #include <EEPROM.h>
  9. #include <SPI.h>
  10. #include <SD.h>
  11. #include <TFT.h>
  12.  
  13.  
  14. #if defined(__AVR__)
  15.   #define imagedatatype  unsigned int
  16. #elif defined(__PIC32MX__)
  17.   #define imagedatatype  unsigned short
  18. #elif defined(__arm__)
  19.   #define imagedatatype  unsigned short
  20. #endif
  21.  
  22.  
  23.  
  24. const int DS1307 = 0x68;
  25. int address = 0;
  26. byte value;
  27.  
  28. extern uint8_t SmallFont[];
  29. extern uint8_t BigFont[];
  30. extern uint8_t SevenSegNumFont[];
  31.  
  32. RTC_DS1307 RTC;
  33. UTFT myGLCD(SSD1289,38,39,40,41);
  34. UTouch  myTouch( 6, 5, 4, 3, 2);
  35. UTFT_Buttons  myButtons(&myGLCD, &myTouch);
  36.  
  37. //extern imagedatatype LogoLum[];
  38. extern imagedatatype LogoValider[];
  39. extern imagedatatype LogoIntraExtra[];
  40. extern imagedatatype LogoBoxFan[];
  41. extern imagedatatype LogoSetting[];
  42.  
  43. //extern unsigned int Logo[0x3840];
  44. extern unsigned int LogoLum[0x640];
  45. extern unsigned int LogoRetour[0x640];
  46. extern unsigned int LogoValider[0x640];
  47. extern unsigned int LogoIntraExtra[0x640];
  48. extern unsigned int LogoBoxFan[14400];
  49. extern unsigned int LogoSetting[14400];
  50.  
  51. int PinCsSd = 53 ;
  52.  
  53. int PinLight = 13 ;
  54.  
  55. int PinRelais_1 = 8;
  56. int PinRelais_2 = 9;
  57. int PinRelais_3 = 10;
  58.  
  59. int PinCapteur_1 = 0;
  60. int PinCapteur_2 = 1;
  61. int PinCapteur_3 = 2;
  62.  
  63. uint8_t PinCapteur_Dht = 11 ;
  64. uint8_t TypeCapteur_Dht = DHT22 ;
  65.  
  66. DHT dht( PinCapteur_Dht, TypeCapteur_Dht ) ;
  67.  
  68.  
  69. /*
  70. #define DHTPIN 19     // what pin we're connected to
  71. #define DHTTYPE DHT22   // DHT 22  (AM2302)
  72. DHT dht(DHTPIN, DHTTYPE);
  73. */
  74.  
  75. int EepromRelais_1 = 8 ;
  76. int EepromRelais_2 = 9 ;
  77. int EepromRelais_3 = 10 ;
  78.  
  79. /*
  80. TFT TFTscreen = TFT(40, dc, 41);
  81. PImage logo;
  82. */
  83. void setup()
  84. {
  85.  
  86. Serial.println("setup");
  87.  
  88. Serial.begin(9600);
  89.  
  90.  
  91.  
  92. initialisationScreen() ;
  93.  
  94.  
  95. initialisationPin() ;
  96.  
  97.  
  98.  
  99. if (!SD.begin( PinCsSd )) {
  100.     Serial.println("Erreur de demarrage!");
  101.     return;
  102.   }
  103.   Serial.println("Carte SD prête.");
  104.  
  105. /*
  106.   logo = TFTscreen.loadImage("logo.bmp");
  107.   if (!logo.isValid()) {
  108.     Serial.println("error while loading arduino.bmp");
  109.   }
  110. }
  111. */
  112. }
  113.  
  114. void loop()
  115. {  
  116.  
  117.  
  118.  
  119.   Serial.println("loop");
  120.  
  121.  
  122.   MenuPrincipal();
  123. }
  124.  
  125. void initialisationPin()
  126. {
  127.   Serial.println("i p");
  128.  
  129.   Wire.begin(1);
  130.   RTC.begin();
  131.   dht.begin();
  132.  
  133.   pinMode( PinRelais_1 , OUTPUT ) ;
  134.   pinMode( PinRelais_2 , OUTPUT ) ;
  135.   pinMode( PinRelais_3 , OUTPUT ) ;
  136.  
  137.   pinMode( PinCapteur_2 , INPUT ) ;
  138.   pinMode( PinCapteur_3 , INPUT ) ;
  139.  
  140.   if( EEPROMLecture( EepromRelais_1 ) == 1 )
  141.     {
  142.       digitalWrite( PinRelais_1, HIGH ) ;
  143.     }
  144.   else
  145.     {
  146.       digitalWrite( PinRelais_1, LOW ) ;
  147.     }
  148.  
  149.   if( EEPROMLecture( EepromRelais_2 ) == 1 )
  150.     {
  151.       digitalWrite( PinRelais_2, HIGH ) ;
  152.     }
  153.   else
  154.     {
  155.       digitalWrite( PinRelais_2, LOW);
  156.     }
  157.  
  158.   if( EEPROMLecture( EepromRelais_3 ) == 1)
  159.     {
  160.       digitalWrite( PinRelais_3, HIGH ) ;
  161.     }
  162.   else
  163.     {
  164.       digitalWrite( PinRelais_3, LOW ) ;
  165.     }
  166.  
  167.   delay(20);  
  168. }
  169.  
  170. void initialisationScreen( )
  171. {
  172.  
  173.   Serial.println(" i s ");
  174.  
  175.   myGLCD.InitLCD();
  176.   delay(20);
  177.   myGLCD.clrScr();
  178.   delay(20);
  179.   myGLCD.fillScr(0, 102, 51);
  180.   //myGLCD.drawBitmap (80, 50, 120, 120, Logo, 1);
  181.   delay(20);
  182.   myGLCD.setFont(SmallFont);
  183.   myGLCD.setBackColor(0, 102, 51);
  184.   myGLCD.setColor(10, 50, 30);
  185.   myGLCD.print("- INITIALISATION -", CENTER, 170);
  186.   myGLCD.print("TACTILE", CENTER, 195);
  187.   myTouch.InitTouch();
  188.   delay(20);
  189.   myTouch.setPrecision(PREC_MEDIUM);
  190.   delay(10);
  191.   myGLCD.print("I2C", CENTER, 215);  
  192.   delay(20);
  193. }
  194.  
  195. void MenuSetting()
  196. {
  197.   myGLCD.clrScr();
  198. }
  199.  
  200. void MenuPrincipal()
  201. {
  202.   Serial.println("mPrinci");
  203.  
  204.  
  205.   myGLCD.clrScr();
  206.   myButtons.deleteAllButtons();
  207.   myGLCD.fillScr(0, 102, 51);
  208.   myButtons.setTextFont(SmallFont);
  209.   myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_BLACK, VGA_BLACK, VGA_GREEN);
  210.  
  211.   int iconLum, iconRelais_1, iconRelais_2 , iconRelais_3 , iconSetting , pressed_button ;  
  212.  
  213. Serial.println("deb ico");
  214.  
  215.  
  216.   iconLum = myButtons.addButton( 2 ,  197 , 40 , 40 , LogoLum ) ;
  217.   iconRelais_1 = myButtons.addButton( 44 , 197 , 40 , 40 , LogoIntraExtra ) ;
  218.   iconRelais_2 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoBoxFan ) ;
  219.   //iconRelais_3 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoIntraExtra ) ;
  220.   iconSetting = myButtons.addButton( 128 , 197 , 40 , 40 , LogoSetting ) ;
  221.  
  222.   Serial.println("fin ico");
  223.  
  224.   myButtons.drawButtons();
  225.   myGLCD.setFont(SmallFont);
  226.  
  227.   /*
  228.   myGLCD.setColor(0,0,0);
  229.   myGLCD.print("Temperature :", 55, 30);
  230.   myGLCD.print("C", 210, 30);
  231.   myGLCD.print("Hygrometrie :", 55, 45);
  232.   myGLCD.print("%", 210, 45);
  233.   myGLCD.print("Lampe :",55, 60);
  234.   myGLCD.print("Vaporisateur :" ,55, 75);
  235.  */
  236.  
  237.  while(1)
  238.  {
  239.   Continue() ;
  240.  
  241.  
  242.    
  243.   myGLCD.setFont(SmallFont);
  244.  
  245.   int dhtTemp = dht.readTemperature() ;
  246.   int dhtHumid = int(dht.readHumidity() ) ;
  247.  
  248. //int testttt = random( 20, 30) ;
  249.  
  250.   myGLCD.print(String( dhtTemp ), 165, 30);
  251.   delay(20);
  252.  
  253.   myGLCD.print(String( dhtHumid ) , 165, 45);
  254.   delay(20);
  255.  
  256.   if( digitalRead( PinRelais_1 ) == HIGH )
  257.   {
  258.     myGLCD.setColor(0,255,0);
  259.     myGLCD.print("ON ", 170, 75);
  260.     myGLCD.setColor(0,0,0);
  261.   }
  262.   else
  263.   {
  264.     myGLCD.setColor(255,0,0);
  265.     myGLCD.print("OFF", 170, 75);
  266.     myGLCD.setColor(0,0,0);
  267.   }
  268.    
  269.  
  270.  
  271.   if( digitalRead( PinLight ) == HIGH )
  272.   {
  273.     myGLCD.setColor(0,255,0);
  274.     myGLCD.print("ON ", 170, 60);
  275.     myGLCD.setColor(0,0,0);
  276.   }
  277.   else
  278.   {
  279.     myGLCD.setColor(255,0,0);
  280.     myGLCD.print("OFF", 170, 60);
  281.     myGLCD.setColor(0,0,0);
  282.   }
  283.  
  284.  
  285.    
  286.   myGLCD.setFont(BigFont);
  287.  
  288.   if ( myTouch.dataAvailable() == true )
  289.     {
  290.      
  291.       Serial.println("tactile");
  292.      
  293.       pressed_button = myButtons.checkButtons() ;
  294.  
  295.       if ( pressed_button == iconLum )
  296.       {
  297.         MenuLum() ;
  298.       }
  299.      
  300.       if ( pressed_button == iconRelais_1 )
  301.       {
  302.         MenuIntraExtra() ;
  303.       }
  304.  
  305.       if ( pressed_button == iconRelais_2 )
  306.       {
  307.         MenuBoxFan() ;
  308.       }
  309. /*
  310.       if ( pressed_button == iconRelais_3 )
  311.       {
  312.         MenuBoxFan() ;
  313.       }
  314. */
  315.       if ( pressed_button == iconSetting )
  316.       {
  317.         MenuSetting() ;
  318.       }
  319.      
  320.     }
  321.  }
  322.  
  323. }
  324.  
  325. void MenuBoxFan()
  326. {
  327.     int hygro1 , hygro2 ;
  328.    
  329.     myGLCD.clrScr();
  330.     myButtons.deleteAllButtons();
  331.     delay(20);
  332.     myGLCD.fillScr(0, 102, 51);
  333.     myGLCD.setColor(10,50,30);
  334.     myGLCD.setFont(SmallFont);
  335.    
  336.    
  337.     while(1)
  338.     {
  339.       hygro1 = analogRead( PinCapteur_1 ) ;
  340.       hygro2 = analogRead( PinCapteur_2 ) ;
  341.      
  342.  
  343.       //myGLCD.clrScr();
  344.       delay(20);
  345.       //myGLCD.fillScr(0, 102, 51);
  346.  
  347.       if ( hygro1 > 0 && hygro1 < 309 )
  348.       {
  349.         myGLCD.print( "Terre humide" , 20 , 150 ) ;
  350.        
  351.       }
  352.       else if ( hygro1 > 201 && hygro1 < 450 )
  353.       {
  354.         myGLCD.print( "Terre sec" , 20 , 150 ) ;
  355.       }
  356.       else
  357.       {
  358.         myGLCD.print( "Air" , 20 , 150 ) ;
  359.       }
  360.      
  361.       myGLCD.print( String ( hygro1 ) , 20 , 170 ) ;
  362.  
  363.  
  364.       if ( hygro2 > 0 && hygro2 < 309 )
  365.       {
  366.         myGLCD.print( "Terre humide" , 218, 150 ) ;
  367.        
  368.       }
  369.       else if ( hygro2 > 201 && hygro2 < 450 )
  370.       {
  371.         myGLCD.print( "Terre sec" , 218 , 150 ) ;
  372.       }
  373.       else
  374.       {
  375.         myGLCD.print( "Air" , 218 , 150 ) ;
  376.       }
  377.  
  378.      
  379.      
  380.       myGLCD.print( String ( hygro2 ) , 218 , 170 ) ;
  381.  
  382.       //delay (1000);
  383.  
  384.      
  385.     }
  386.  
  387.  
  388.    
  389.  
  390.  
  391.     /*
  392.     myGLCD.print("ON", 72, 170);
  393.     myGLCD.print("OFF", 218, 170);
  394.     myGLCD.setColor(0,0,0);
  395.     myGLCD.setFont(SmallFont);
  396.     myGLCD.print("Lumiere", 4, 4);
  397.            
  398.       myGLCD.clrScr();
  399.  
  400.       tmp=digitalRead( moistureDO );
  401.   if ( tmp != DO )
  402.   {
  403.     DO=tmp;
  404.     Serial.print("D=");
  405.     Serial.println(DO);
  406.   }
  407.  */
  408.  
  409.  
  410.  
  411.  
  412. }
  413.  
  414.  
  415. void MenuLum()
  416. {
  417.   myGLCD.clrScr();
  418.   myButtons.deleteAllButtons();
  419.   delay(20);
  420.   myGLCD.fillScr(0, 102, 51);
  421.   myGLCD.setColor(10,50,30);
  422.   myGLCD.print("ON", 72, 170);
  423.    myGLCD.print("OFF", 218, 170);
  424.   myGLCD.setColor(0,0,0);
  425.   myGLCD.setFont(SmallFont);
  426.   myGLCD.print("Lumiere", 4, 4);
  427.   int MenuPrinc, PlusOnHeure, PlusOnMinute, PlusOffHeure, PlusOffMinute, pressed_button, MoinOnHeure, MoinOnMinute, MoinOffHeure, MoinOffMinute, Valider;
  428.   int HeureOn = EEPROMLecture(0);
  429.   int HeureOff = EEPROMLecture(1);
  430.   int MinuteOn = EEPROMLecture(2);
  431.   int MinuteOff = EEPROMLecture(3);
  432.   myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_BLACK, VGA_RED, VGA_GREEN);
  433.   MenuPrinc = myButtons.addButton( 2,  197, 40,  40, LogoRetour);
  434.   PlusOnHeure = myButtons.addButton(50, 75,  30, 30, "+");
  435.   PlusOnMinute = myButtons.addButton(98, 75, 30, 30, "+");
  436.   PlusOffHeure = myButtons.addButton(200, 75, 30, 30, "+");
  437.   PlusOffMinute = myButtons.addButton(252, 75, 30, 30, "+");
  438.  
  439.   MoinOnHeure = myButtons.addButton(50, 135, 30, 30, "-");
  440.   MoinOnMinute = myButtons.addButton(98, 135, 30, 30, "-");
  441.   MoinOffHeure = myButtons.addButton(200, 135, 30, 30, "-");
  442.   MoinOffMinute = myButtons.addButton(252, 135, 30, 30, "-");
  443.   Valider = myButtons.addButton( 278,  197, 40,  40, LogoValider);
  444.    
  445.   myButtons.setTextFont(BigFont);
  446.  
  447.    
  448.  
  449.   myButtons.drawButtons();
  450.  
  451.   while(1)
  452.   {
  453.     Continue();
  454.  
  455.  if(HeureOn < 10)                                                  // Affichage de l'heure d'allumage des lampes
  456.       {
  457.         myGLCD.print("0", 50, 112);
  458.         myGLCD.print(String(HeureOn), 66, 112);
  459.         myGLCD.print(":", 82, 112);
  460.       }  
  461.     else
  462.       {
  463.           myGLCD.print(String(HeureOn), 50, 112);
  464.           myGLCD.print(":", 82, 112);
  465.       }
  466.      
  467.    if(MinuteOn < 10)                                              // Affichage des minute lampe allumees
  468.       {
  469.         myGLCD.print("0", 98, 112);
  470.         myGLCD.print(String(MinuteOn), 114, 112);
  471.       }  
  472.     else
  473.       {
  474.           myGLCD.print(String(MinuteOn), 98, 112);
  475.       }
  476.  
  477. if(HeureOff < 10)                                                // Affichage de l'heure d'eteignage des lampes
  478.       {
  479.         myGLCD.print("0", 200, 112);
  480.         myGLCD.print(String(HeureOff), 216, 112);
  481.         myGLCD.print(":", 236, 112);
  482.       }  
  483.     else
  484.       {
  485.           myGLCD.print(String(HeureOff), 200, 112);
  486.           myGLCD.print(":", 236, 112);
  487.       }
  488.      
  489.    if(MinuteOff < 10)                                            // Affichage des minutes d'eteignage des lampes
  490.       {
  491.         myGLCD.print("0", 252, 112);
  492.         myGLCD.print(String(MinuteOff), 268, 112);
  493.       }  
  494.     else
  495.       {
  496.           myGLCD.print(String(MinuteOff), 252, 112);
  497.       }
  498.      
  499.      
  500.                                                                //Tactile
  501.  
  502.     if (myTouch.dataAvailable() == true)
  503.     {
  504.       pressed_button = myButtons.checkButtons();
  505.  
  506.     if (pressed_button==PlusOnHeure)
  507.       {
  508.         if(HeureOn <23)
  509.          {
  510.             HeureOn++ ;
  511.          }
  512.          else
  513.          {
  514.           HeureOn = 0 ;
  515.          }
  516.       }
  517.      
  518.       if(pressed_button==MoinOnHeure)
  519.       {
  520.         if(HeureOn > 0)
  521.         {
  522.           HeureOn-- ;
  523.         }
  524.         else
  525.         {
  526.           HeureOn = 23 ;
  527.         }
  528.       }
  529.       if(pressed_button==PlusOnMinute)
  530.       {
  531.         if(MinuteOn < 59)
  532.         {
  533.           MinuteOn++ ;
  534.         }
  535.         else
  536.         {
  537.           MinuteOn = 0 ;
  538.         }
  539.       }
  540.       if(pressed_button==MoinOnMinute)
  541.       {
  542.         if(MinuteOn > 0)
  543.         {
  544.           MinuteOn-- ;
  545.         }
  546.         else
  547.         {
  548.           MinuteOn = 59 ;
  549.         }
  550.       }
  551.       if(pressed_button==PlusOffHeure)
  552.       {
  553.         if(HeureOff < 23)
  554.         {
  555.           HeureOff++ ;
  556.         }
  557.         else
  558.         {
  559.           HeureOff = 0 ;
  560.         }
  561.       }
  562.       if(pressed_button==MoinOffHeure)
  563.       {
  564.         if(HeureOff > 0)
  565.         {
  566.           HeureOff-- ;
  567.         }
  568.         else
  569.         {
  570.           HeureOff = 23 ;
  571.         }
  572.       }
  573.       if(pressed_button==PlusOffMinute)
  574.       {
  575.         if(MinuteOff < 59)
  576.         {
  577.         MinuteOff++;
  578.         }
  579.         else
  580.         {
  581.           MinuteOff = 0 ;
  582.         }
  583.       }
  584.       if(pressed_button==MoinOffMinute)
  585.       {
  586.         if(MinuteOff > 0)
  587.         {
  588.         MinuteOff-- ;
  589.         }
  590.         else
  591.         {
  592.           MinuteOff = 59 ;
  593.         }
  594.       }
  595.      
  596.       if (pressed_button==MenuPrinc)
  597.       {
  598.         MenuPrincipal();
  599.       }
  600.      
  601.       if (pressed_button==Valider)
  602.       {
  603.         EEPROMEcriture(HeureOn, 0);
  604.         EEPROMEcriture(HeureOff, 1);
  605.         EEPROMEcriture(MinuteOn, 2);
  606.         EEPROMEcriture(MinuteOff, 3);
  607.        
  608.         MenuPrincipal();
  609.       }
  610.      
  611.     }
  612.  }
  613. }
  614. void MenuIntraExtra()
  615. {
  616.   Continue();
  617.   myGLCD.clrScr();
  618.   myButtons.deleteAllButtons();
  619.   delay(20);
  620.   myGLCD.fillScr(0, 102, 51);
  621.   myGLCD.setColor(10,50,30);
  622.   myGLCD.setFont(SmallFont);
  623.   myGLCD.print("Temperature", 45, 170);
  624.   myGLCD.print("Hygrometrie", 200, 170);
  625.   myGLCD.print("Min", 54, 60);
  626.   myGLCD.print("Max", 104, 60);
  627.   myGLCD.print("Min", 203, 60);
  628.   myGLCD.print("Max", 256, 60);
  629.   myGLCD.setColor(0,0,0);
  630.   myGLCD.print("Ventilation", 4, 4);
  631.   int MenuPrinc, PlusOnVentilTemp, PlusOffVentilTemp, PlusOnVentilHum, PlusOffVentilHum, pressed_button, MoinOnVentilTemp, MoinOnVentilHum, MoinOffVentilTemp, MoinOffVentilHum, Valider;
  632.   int VentilTempOn = EEPROMLecture(4);
  633.   int VentilTempOff = EEPROMLecture(5);
  634.   int VentilHumOn = EEPROMLecture(6);
  635.   int VentilHumOff = EEPROMLecture(7);
  636.   myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_BLACK, VGA_RED, VGA_GREEN);
  637.   MenuPrinc = myButtons.addButton( 2,  197, 40,  40, LogoRetour);
  638.   PlusOnVentilTemp = myButtons.addButton(50, 75,  30, 30, "+");
  639.   PlusOffVentilTemp = myButtons.addButton(98, 75, 30, 30, "+");
  640.   PlusOnVentilHum = myButtons.addButton(200, 75, 30, 30, "+");
  641.   PlusOffVentilHum = myButtons.addButton(252, 75, 30, 30, "+");
  642.  
  643.   MoinOnVentilTemp = myButtons.addButton(50, 135, 30, 30, "-");
  644.   MoinOffVentilTemp = myButtons.addButton(98, 135, 30, 30, "-");
  645.   MoinOnVentilHum = myButtons.addButton(200, 135, 30, 30, "-");
  646.   MoinOffVentilHum = myButtons.addButton(252, 135, 30, 30, "-");
  647.   Valider = myButtons.addButton( 278,  197, 40,  40, LogoValider);
  648.   myGLCD.print("C", 80, 112);
  649.   myGLCD.print("C", 128, 112);
  650.   myGLCD.print("%", 232, 112);
  651.   myGLCD.print("%", 284, 112);
  652.    
  653.   myButtons.setTextFont(BigFont);
  654.   myButtons.drawButtons();
  655.  
  656.   while(1)
  657.   {
  658.     Continue();
  659.     if(VentilTempOn < 10)                                                  // Affichage de l'heure d'allumage des lampes
  660.       {
  661.         myGLCD.print("0", 45, 112);
  662.         myGLCD.print(String(VentilTempOn), 61, 112);
  663.      
  664.       }  
  665.     else
  666.       {
  667.           myGLCD.print(String(VentilTempOn), 45, 112);
  668.    
  669.       }
  670.      
  671.    if(VentilTempOff < 10)                                              // Affichage des minute lampe allumees
  672.       {
  673.         myGLCD.print("0", 93, 112);
  674.         myGLCD.print(String(VentilTempOff), 109, 112);
  675.       }  
  676.     else
  677.       {
  678.           myGLCD.print(String(VentilTempOff), 93, 112);
  679.       }
  680.  
  681. if(VentilHumOn < 10)                                                // Affichage de l'heure d'eteignage des lampes
  682.       {
  683.         myGLCD.print("0", 195, 112);
  684.         myGLCD.print(String(VentilHumOn), 211, 112);
  685.       }  
  686.     else
  687.       {
  688.           myGLCD.print(String(VentilHumOn), 195, 112);
  689.       }
  690.      
  691.    if(VentilHumOff < 10)                                            // Affichage des minutes d'eteignage des lampes
  692.       {
  693.         myGLCD.print("0", 247, 112);
  694.         myGLCD.print(String(VentilHumOff), 263, 112);
  695.       }  
  696.     else
  697.       {
  698.           myGLCD.print(String(VentilHumOff), 247, 112);
  699.       }
  700.      
  701.      
  702.                                                                //Tactile
  703.  
  704.     if (myTouch.dataAvailable() == true)
  705.     {
  706.       pressed_button = myButtons.checkButtons();
  707.  
  708.     if (pressed_button==PlusOnVentilTemp)
  709.       {
  710.         if(VentilTempOn <98)
  711.        {
  712.           VentilTempOn++;
  713.        }
  714.       }
  715.       if(pressed_button==PlusOffVentilTemp)
  716.       {
  717.         if(VentilTempOff <98)
  718.         {
  719.           VentilTempOff++;
  720.         }
  721.       }
  722.       if(pressed_button==PlusOnVentilHum)
  723.       {
  724.         if(VentilHumOn < 98)
  725.         {
  726.           VentilHumOn++;
  727.         }
  728.       }
  729.       if(pressed_button==PlusOffVentilHum)
  730.       {
  731.         if(VentilHumOff < 98)
  732.         {
  733.           VentilHumOff++;
  734.         }
  735.       }
  736.       if(pressed_button==MoinOnVentilTemp)
  737.       {
  738.         if(VentilTempOn > 0)
  739.         {
  740.           VentilTempOn--;
  741.         }
  742.       }
  743.       if(pressed_button==MoinOffVentilTemp)
  744.       {
  745.         if(VentilTempOff > 0)
  746.         {
  747.           VentilTempOff--;
  748.         }
  749.       }
  750.       if(pressed_button==MoinOnVentilHum)
  751.       {
  752.         if(VentilHumOn > 0)
  753.         {
  754.         VentilHumOn--;
  755.         }
  756.       }
  757.       if(pressed_button==MoinOffVentilHum)
  758.       {
  759.         if(VentilHumOff > 0)
  760.         {
  761.         VentilHumOff--;
  762.         }
  763.       }
  764.      
  765.       if (pressed_button==MenuPrinc)
  766.       {
  767.         MenuPrincipal();
  768.       }
  769.      
  770.       if (pressed_button==Valider)
  771.       {
  772.         EEPROMEcriture(VentilTempOn, 4);
  773.         EEPROMEcriture(VentilTempOff, 5);
  774.         EEPROMEcriture(VentilHumOn, 6);
  775.         EEPROMEcriture(VentilHumOff, 7);
  776.        
  777.         MenuPrincipal();
  778.       }
  779.      
  780.     }
  781.   }
  782. }
  783.  
  784.  
  785. void EEPROMEcriture(int Val, int addr)
  786. {
  787.  
  788.   EEPROM.write(addr, Val);
  789.   delay(10);
  790.  
  791. }
  792.  
  793. int EEPROMLecture(int addr)
  794. {
  795.   byte Val = EEPROM.read(addr);
  796.   return Val;
  797.   delay(10);
  798. }
  799.  
  800.  
  801. void Continue()                                    //focntion qui tourne toujours en arriere plan
  802.   {
  803.     DateTime now = RTC.now();
  804.     myGLCD.setFont(BigFont);
  805.     if( now.hour() < 10)
  806.       {
  807.         myGLCD.print("0", 192, 2);
  808.         myGLCD.print(String(now.hour()), 208, 2);
  809.         myGLCD.print(":", 224, 2);
  810.       }  
  811.     else
  812.       {
  813.           myGLCD.print(String(now.hour()), 192, 2);
  814.           myGLCD.print(":", 224, 2);
  815.       }
  816.  
  817.     if(now.minute() < 10)
  818.       {
  819.         myGLCD.print("0", 240, 2);
  820.         myGLCD.print(String(now.minute()), 256, 2);
  821.         myGLCD.print(":", 272, 2);
  822.       }  
  823.     else
  824.       {
  825.           myGLCD.print(String(now.minute()), 240, 2);
  826.           myGLCD.print(":", 272, 2);
  827.       }
  828.      
  829.     if(now.second() <10)
  830.     {
  831.       myGLCD.print("0", 288, 2);
  832.       myGLCD.print(String(now.second()), 304, 2);
  833.  
  834.     }
  835.     else
  836.     {
  837.       myGLCD.print(String(now.second()), 288, 2);
  838.      
  839.     }
  840.    
  841. delay(20);
  842.  
  843. int HeureOn = int(EEPROMLecture(0));
  844. int HeureOff = int(EEPROMLecture(1));
  845. int MinuteOn = int(EEPROMLecture(2));
  846. int MinuteOff = int(EEPROMLecture(3));
  847. int VentilTempOn = int(EEPROMLecture(4));
  848. int VentilTempOff = int(EEPROMLecture(5));
  849. int VentilHumOn = int(EEPROMLecture(6));
  850. int VentilHumOff = int(EEPROMLecture(7));
  851.  
  852.  
  853.   /*
  854.   if( int(now.hour()) == HeureOn  && int(now.minute()) == MinuteOn)
  855.    {
  856.     digitalWrite( PinRelai_1 , HIGH);
  857.     EEPROMEcriture(1, 8);
  858.     }
  859.    
  860.   if (int(now.hour()) == HeureOff  && int(now.minute()) == MinuteOff)
  861.    {
  862.     digitalWrite( PinRelai_1 , LOW ) ;
  863.     EEPROMEcriture(0, 8);
  864.    }
  865.    
  866.    if( dht.readHumidity() < VentilHumOn )
  867.    {
  868.      digitalWrite( PinRelai_2 , HIGH ) ;
  869.      EEPROMEcriture(1, 10) ;
  870.    }
  871.    else
  872.    {
  873.      digitalWrite( PinRelai_2 , LOW ) ;
  874.      EEPROMEcriture(0, 10);
  875.    }
  876. */
  877.  
  878.  
  879.  
  880.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement