Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DHT.h"
- #include <UTFT.h>
- #include <UTouch.h>
- #include <UTFT_Buttons.h>
- #include <avr/pgmspace.h>
- #include <Wire.h>
- #include <RTClib.h>
- #include <EEPROM.h>
- #include <SPI.h>
- #include <SD.h>
- #include <TFT.h>
- #if defined(__AVR__)
- #define imagedatatype unsigned int
- #elif defined(__PIC32MX__)
- #define imagedatatype unsigned short
- #elif defined(__arm__)
- #define imagedatatype unsigned short
- #endif
- const int DS1307 = 0x68;
- int address = 0;
- byte value;
- extern uint8_t SmallFont[];
- extern uint8_t BigFont[];
- extern uint8_t SevenSegNumFont[];
- RTC_DS1307 RTC;
- UTFT myGLCD(SSD1289,38,39,40,41);
- UTouch myTouch( 6, 5, 4, 3, 2);
- UTFT_Buttons myButtons(&myGLCD, &myTouch);
- //extern imagedatatype LogoLum[];
- extern imagedatatype LogoValider[];
- extern imagedatatype LogoIntraExtra[];
- extern imagedatatype LogoBoxFan[];
- extern imagedatatype LogoSetting[];
- //extern unsigned int Logo[0x3840];
- extern unsigned int LogoLum[0x640];
- extern unsigned int LogoRetour[0x640];
- extern unsigned int LogoValider[0x640];
- extern unsigned int LogoIntraExtra[0x640];
- extern unsigned int LogoBoxFan[14400];
- extern unsigned int LogoSetting[14400];
- int PinCsSd = 53 ;
- int PinLight = 13 ;
- int PinRelais_1 = 8;
- int PinRelais_2 = 9;
- int PinRelais_3 = 10;
- int PinCapteur_1 = 0;
- int PinCapteur_2 = 1;
- int PinCapteur_3 = 2;
- uint8_t PinCapteur_Dht = 11 ;
- uint8_t TypeCapteur_Dht = DHT22 ;
- DHT dht( PinCapteur_Dht, TypeCapteur_Dht ) ;
- /*
- #define DHTPIN 19 // what pin we're connected to
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- DHT dht(DHTPIN, DHTTYPE);
- */
- int EepromRelais_1 = 8 ;
- int EepromRelais_2 = 9 ;
- int EepromRelais_3 = 10 ;
- /*
- TFT TFTscreen = TFT(40, dc, 41);
- PImage logo;
- */
- void setup()
- {
- Serial.println("setup");
- Serial.begin(9600);
- initialisationScreen() ;
- initialisationPin() ;
- if (!SD.begin( PinCsSd )) {
- Serial.println("Erreur de demarrage!");
- return;
- }
- Serial.println("Carte SD prête.");
- /*
- logo = TFTscreen.loadImage("logo.bmp");
- if (!logo.isValid()) {
- Serial.println("error while loading arduino.bmp");
- }
- }
- */
- }
- void loop()
- {
- Serial.println("loop");
- MenuPrincipal();
- }
- void initialisationPin()
- {
- Serial.println("i p");
- Wire.begin(1);
- RTC.begin();
- dht.begin();
- pinMode( PinRelais_1 , OUTPUT ) ;
- pinMode( PinRelais_2 , OUTPUT ) ;
- pinMode( PinRelais_3 , OUTPUT ) ;
- pinMode( PinCapteur_2 , INPUT ) ;
- pinMode( PinCapteur_3 , INPUT ) ;
- if( EEPROMLecture( EepromRelais_1 ) == 1 )
- {
- digitalWrite( PinRelais_1, HIGH ) ;
- }
- else
- {
- digitalWrite( PinRelais_1, LOW ) ;
- }
- if( EEPROMLecture( EepromRelais_2 ) == 1 )
- {
- digitalWrite( PinRelais_2, HIGH ) ;
- }
- else
- {
- digitalWrite( PinRelais_2, LOW);
- }
- if( EEPROMLecture( EepromRelais_3 ) == 1)
- {
- digitalWrite( PinRelais_3, HIGH ) ;
- }
- else
- {
- digitalWrite( PinRelais_3, LOW ) ;
- }
- delay(20);
- }
- void initialisationScreen( )
- {
- Serial.println(" i s ");
- myGLCD.InitLCD();
- delay(20);
- myGLCD.clrScr();
- delay(20);
- myGLCD.fillScr(0, 102, 51);
- //myGLCD.drawBitmap (80, 50, 120, 120, Logo, 1);
- delay(20);
- myGLCD.setFont(SmallFont);
- myGLCD.setBackColor(0, 102, 51);
- myGLCD.setColor(10, 50, 30);
- myGLCD.print("- INITIALISATION -", CENTER, 170);
- myGLCD.print("TACTILE", CENTER, 195);
- myTouch.InitTouch();
- delay(20);
- myTouch.setPrecision(PREC_MEDIUM);
- delay(10);
- myGLCD.print("I2C", CENTER, 215);
- delay(20);
- }
- void MenuSetting()
- {
- myGLCD.clrScr();
- }
- void MenuPrincipal()
- {
- Serial.println("mPrinci");
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- myGLCD.fillScr(0, 102, 51);
- myButtons.setTextFont(SmallFont);
- myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_BLACK, VGA_BLACK, VGA_GREEN);
- int iconLum, iconRelais_1, iconRelais_2 , iconRelais_3 , iconSetting , pressed_button ;
- Serial.println("deb ico");
- iconLum = myButtons.addButton( 2 , 197 , 40 , 40 , LogoLum ) ;
- iconRelais_1 = myButtons.addButton( 44 , 197 , 40 , 40 , LogoIntraExtra ) ;
- iconRelais_2 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoBoxFan ) ;
- //iconRelais_3 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoIntraExtra ) ;
- iconSetting = myButtons.addButton( 128 , 197 , 40 , 40 , LogoSetting ) ;
- Serial.println("fin ico");
- myButtons.drawButtons();
- myGLCD.setFont(SmallFont);
- /*
- myGLCD.setColor(0,0,0);
- myGLCD.print("Temperature :", 55, 30);
- myGLCD.print("C", 210, 30);
- myGLCD.print("Hygrometrie :", 55, 45);
- myGLCD.print("%", 210, 45);
- myGLCD.print("Lampe :",55, 60);
- myGLCD.print("Vaporisateur :" ,55, 75);
- */
- while(1)
- {
- Continue() ;
- myGLCD.setFont(SmallFont);
- int dhtTemp = dht.readTemperature() ;
- int dhtHumid = int(dht.readHumidity() ) ;
- //int testttt = random( 20, 30) ;
- myGLCD.print(String( dhtTemp ), 165, 30);
- delay(20);
- myGLCD.print(String( dhtHumid ) , 165, 45);
- delay(20);
- if( digitalRead( PinRelais_1 ) == HIGH )
- {
- myGLCD.setColor(0,255,0);
- myGLCD.print("ON ", 170, 75);
- myGLCD.setColor(0,0,0);
- }
- else
- {
- myGLCD.setColor(255,0,0);
- myGLCD.print("OFF", 170, 75);
- myGLCD.setColor(0,0,0);
- }
- if( digitalRead( PinLight ) == HIGH )
- {
- myGLCD.setColor(0,255,0);
- myGLCD.print("ON ", 170, 60);
- myGLCD.setColor(0,0,0);
- }
- else
- {
- myGLCD.setColor(255,0,0);
- myGLCD.print("OFF", 170, 60);
- myGLCD.setColor(0,0,0);
- }
- myGLCD.setFont(BigFont);
- if ( myTouch.dataAvailable() == true )
- {
- Serial.println("tactile");
- pressed_button = myButtons.checkButtons() ;
- if ( pressed_button == iconLum )
- {
- MenuLum() ;
- }
- if ( pressed_button == iconRelais_1 )
- {
- MenuIntraExtra() ;
- }
- if ( pressed_button == iconRelais_2 )
- {
- MenuBoxFan() ;
- }
- /*
- if ( pressed_button == iconRelais_3 )
- {
- MenuBoxFan() ;
- }
- */
- if ( pressed_button == iconSetting )
- {
- MenuSetting() ;
- }
- }
- }
- }
- void MenuBoxFan()
- {
- int hygro1 , hygro2 ;
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- delay(20);
- myGLCD.fillScr(0, 102, 51);
- myGLCD.setColor(10,50,30);
- myGLCD.setFont(SmallFont);
- while(1)
- {
- hygro1 = analogRead( PinCapteur_1 ) ;
- hygro2 = analogRead( PinCapteur_2 ) ;
- //myGLCD.clrScr();
- delay(20);
- //myGLCD.fillScr(0, 102, 51);
- if ( hygro1 > 0 && hygro1 < 309 )
- {
- myGLCD.print( "Terre humide" , 20 , 150 ) ;
- }
- else if ( hygro1 > 201 && hygro1 < 450 )
- {
- myGLCD.print( "Terre sec" , 20 , 150 ) ;
- }
- else
- {
- myGLCD.print( "Air" , 20 , 150 ) ;
- }
- myGLCD.print( String ( hygro1 ) , 20 , 170 ) ;
- if ( hygro2 > 0 && hygro2 < 309 )
- {
- myGLCD.print( "Terre humide" , 218, 150 ) ;
- }
- else if ( hygro2 > 201 && hygro2 < 450 )
- {
- myGLCD.print( "Terre sec" , 218 , 150 ) ;
- }
- else
- {
- myGLCD.print( "Air" , 218 , 150 ) ;
- }
- myGLCD.print( String ( hygro2 ) , 218 , 170 ) ;
- //delay (1000);
- }
- /*
- myGLCD.print("ON", 72, 170);
- myGLCD.print("OFF", 218, 170);
- myGLCD.setColor(0,0,0);
- myGLCD.setFont(SmallFont);
- myGLCD.print("Lumiere", 4, 4);
- myGLCD.clrScr();
- tmp=digitalRead( moistureDO );
- if ( tmp != DO )
- {
- DO=tmp;
- Serial.print("D=");
- Serial.println(DO);
- }
- */
- }
- void MenuLum()
- {
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- delay(20);
- myGLCD.fillScr(0, 102, 51);
- myGLCD.setColor(10,50,30);
- myGLCD.print("ON", 72, 170);
- myGLCD.print("OFF", 218, 170);
- myGLCD.setColor(0,0,0);
- myGLCD.setFont(SmallFont);
- myGLCD.print("Lumiere", 4, 4);
- int MenuPrinc, PlusOnHeure, PlusOnMinute, PlusOffHeure, PlusOffMinute, pressed_button, MoinOnHeure, MoinOnMinute, MoinOffHeure, MoinOffMinute, Valider;
- int HeureOn = EEPROMLecture(0);
- int HeureOff = EEPROMLecture(1);
- int MinuteOn = EEPROMLecture(2);
- int MinuteOff = EEPROMLecture(3);
- myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_BLACK, VGA_RED, VGA_GREEN);
- MenuPrinc = myButtons.addButton( 2, 197, 40, 40, LogoRetour);
- PlusOnHeure = myButtons.addButton(50, 75, 30, 30, "+");
- PlusOnMinute = myButtons.addButton(98, 75, 30, 30, "+");
- PlusOffHeure = myButtons.addButton(200, 75, 30, 30, "+");
- PlusOffMinute = myButtons.addButton(252, 75, 30, 30, "+");
- MoinOnHeure = myButtons.addButton(50, 135, 30, 30, "-");
- MoinOnMinute = myButtons.addButton(98, 135, 30, 30, "-");
- MoinOffHeure = myButtons.addButton(200, 135, 30, 30, "-");
- MoinOffMinute = myButtons.addButton(252, 135, 30, 30, "-");
- Valider = myButtons.addButton( 278, 197, 40, 40, LogoValider);
- myButtons.setTextFont(BigFont);
- myButtons.drawButtons();
- while(1)
- {
- Continue();
- if(HeureOn < 10) // Affichage de l'heure d'allumage des lampes
- {
- myGLCD.print("0", 50, 112);
- myGLCD.print(String(HeureOn), 66, 112);
- myGLCD.print(":", 82, 112);
- }
- else
- {
- myGLCD.print(String(HeureOn), 50, 112);
- myGLCD.print(":", 82, 112);
- }
- if(MinuteOn < 10) // Affichage des minute lampe allumees
- {
- myGLCD.print("0", 98, 112);
- myGLCD.print(String(MinuteOn), 114, 112);
- }
- else
- {
- myGLCD.print(String(MinuteOn), 98, 112);
- }
- if(HeureOff < 10) // Affichage de l'heure d'eteignage des lampes
- {
- myGLCD.print("0", 200, 112);
- myGLCD.print(String(HeureOff), 216, 112);
- myGLCD.print(":", 236, 112);
- }
- else
- {
- myGLCD.print(String(HeureOff), 200, 112);
- myGLCD.print(":", 236, 112);
- }
- if(MinuteOff < 10) // Affichage des minutes d'eteignage des lampes
- {
- myGLCD.print("0", 252, 112);
- myGLCD.print(String(MinuteOff), 268, 112);
- }
- else
- {
- myGLCD.print(String(MinuteOff), 252, 112);
- }
- //Tactile
- if (myTouch.dataAvailable() == true)
- {
- pressed_button = myButtons.checkButtons();
- if (pressed_button==PlusOnHeure)
- {
- if(HeureOn <23)
- {
- HeureOn++ ;
- }
- else
- {
- HeureOn = 0 ;
- }
- }
- if(pressed_button==MoinOnHeure)
- {
- if(HeureOn > 0)
- {
- HeureOn-- ;
- }
- else
- {
- HeureOn = 23 ;
- }
- }
- if(pressed_button==PlusOnMinute)
- {
- if(MinuteOn < 59)
- {
- MinuteOn++ ;
- }
- else
- {
- MinuteOn = 0 ;
- }
- }
- if(pressed_button==MoinOnMinute)
- {
- if(MinuteOn > 0)
- {
- MinuteOn-- ;
- }
- else
- {
- MinuteOn = 59 ;
- }
- }
- if(pressed_button==PlusOffHeure)
- {
- if(HeureOff < 23)
- {
- HeureOff++ ;
- }
- else
- {
- HeureOff = 0 ;
- }
- }
- if(pressed_button==MoinOffHeure)
- {
- if(HeureOff > 0)
- {
- HeureOff-- ;
- }
- else
- {
- HeureOff = 23 ;
- }
- }
- if(pressed_button==PlusOffMinute)
- {
- if(MinuteOff < 59)
- {
- MinuteOff++;
- }
- else
- {
- MinuteOff = 0 ;
- }
- }
- if(pressed_button==MoinOffMinute)
- {
- if(MinuteOff > 0)
- {
- MinuteOff-- ;
- }
- else
- {
- MinuteOff = 59 ;
- }
- }
- if (pressed_button==MenuPrinc)
- {
- MenuPrincipal();
- }
- if (pressed_button==Valider)
- {
- EEPROMEcriture(HeureOn, 0);
- EEPROMEcriture(HeureOff, 1);
- EEPROMEcriture(MinuteOn, 2);
- EEPROMEcriture(MinuteOff, 3);
- MenuPrincipal();
- }
- }
- }
- }
- void MenuIntraExtra()
- {
- Continue();
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- delay(20);
- myGLCD.fillScr(0, 102, 51);
- myGLCD.setColor(10,50,30);
- myGLCD.setFont(SmallFont);
- myGLCD.print("Temperature", 45, 170);
- myGLCD.print("Hygrometrie", 200, 170);
- myGLCD.print("Min", 54, 60);
- myGLCD.print("Max", 104, 60);
- myGLCD.print("Min", 203, 60);
- myGLCD.print("Max", 256, 60);
- myGLCD.setColor(0,0,0);
- myGLCD.print("Ventilation", 4, 4);
- int MenuPrinc, PlusOnVentilTemp, PlusOffVentilTemp, PlusOnVentilHum, PlusOffVentilHum, pressed_button, MoinOnVentilTemp, MoinOnVentilHum, MoinOffVentilTemp, MoinOffVentilHum, Valider;
- int VentilTempOn = EEPROMLecture(4);
- int VentilTempOff = EEPROMLecture(5);
- int VentilHumOn = EEPROMLecture(6);
- int VentilHumOff = EEPROMLecture(7);
- myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_BLACK, VGA_RED, VGA_GREEN);
- MenuPrinc = myButtons.addButton( 2, 197, 40, 40, LogoRetour);
- PlusOnVentilTemp = myButtons.addButton(50, 75, 30, 30, "+");
- PlusOffVentilTemp = myButtons.addButton(98, 75, 30, 30, "+");
- PlusOnVentilHum = myButtons.addButton(200, 75, 30, 30, "+");
- PlusOffVentilHum = myButtons.addButton(252, 75, 30, 30, "+");
- MoinOnVentilTemp = myButtons.addButton(50, 135, 30, 30, "-");
- MoinOffVentilTemp = myButtons.addButton(98, 135, 30, 30, "-");
- MoinOnVentilHum = myButtons.addButton(200, 135, 30, 30, "-");
- MoinOffVentilHum = myButtons.addButton(252, 135, 30, 30, "-");
- Valider = myButtons.addButton( 278, 197, 40, 40, LogoValider);
- myGLCD.print("C", 80, 112);
- myGLCD.print("C", 128, 112);
- myGLCD.print("%", 232, 112);
- myGLCD.print("%", 284, 112);
- myButtons.setTextFont(BigFont);
- myButtons.drawButtons();
- while(1)
- {
- Continue();
- if(VentilTempOn < 10) // Affichage de l'heure d'allumage des lampes
- {
- myGLCD.print("0", 45, 112);
- myGLCD.print(String(VentilTempOn), 61, 112);
- }
- else
- {
- myGLCD.print(String(VentilTempOn), 45, 112);
- }
- if(VentilTempOff < 10) // Affichage des minute lampe allumees
- {
- myGLCD.print("0", 93, 112);
- myGLCD.print(String(VentilTempOff), 109, 112);
- }
- else
- {
- myGLCD.print(String(VentilTempOff), 93, 112);
- }
- if(VentilHumOn < 10) // Affichage de l'heure d'eteignage des lampes
- {
- myGLCD.print("0", 195, 112);
- myGLCD.print(String(VentilHumOn), 211, 112);
- }
- else
- {
- myGLCD.print(String(VentilHumOn), 195, 112);
- }
- if(VentilHumOff < 10) // Affichage des minutes d'eteignage des lampes
- {
- myGLCD.print("0", 247, 112);
- myGLCD.print(String(VentilHumOff), 263, 112);
- }
- else
- {
- myGLCD.print(String(VentilHumOff), 247, 112);
- }
- //Tactile
- if (myTouch.dataAvailable() == true)
- {
- pressed_button = myButtons.checkButtons();
- if (pressed_button==PlusOnVentilTemp)
- {
- if(VentilTempOn <98)
- {
- VentilTempOn++;
- }
- }
- if(pressed_button==PlusOffVentilTemp)
- {
- if(VentilTempOff <98)
- {
- VentilTempOff++;
- }
- }
- if(pressed_button==PlusOnVentilHum)
- {
- if(VentilHumOn < 98)
- {
- VentilHumOn++;
- }
- }
- if(pressed_button==PlusOffVentilHum)
- {
- if(VentilHumOff < 98)
- {
- VentilHumOff++;
- }
- }
- if(pressed_button==MoinOnVentilTemp)
- {
- if(VentilTempOn > 0)
- {
- VentilTempOn--;
- }
- }
- if(pressed_button==MoinOffVentilTemp)
- {
- if(VentilTempOff > 0)
- {
- VentilTempOff--;
- }
- }
- if(pressed_button==MoinOnVentilHum)
- {
- if(VentilHumOn > 0)
- {
- VentilHumOn--;
- }
- }
- if(pressed_button==MoinOffVentilHum)
- {
- if(VentilHumOff > 0)
- {
- VentilHumOff--;
- }
- }
- if (pressed_button==MenuPrinc)
- {
- MenuPrincipal();
- }
- if (pressed_button==Valider)
- {
- EEPROMEcriture(VentilTempOn, 4);
- EEPROMEcriture(VentilTempOff, 5);
- EEPROMEcriture(VentilHumOn, 6);
- EEPROMEcriture(VentilHumOff, 7);
- MenuPrincipal();
- }
- }
- }
- }
- void EEPROMEcriture(int Val, int addr)
- {
- EEPROM.write(addr, Val);
- delay(10);
- }
- int EEPROMLecture(int addr)
- {
- byte Val = EEPROM.read(addr);
- return Val;
- delay(10);
- }
- void Continue() //focntion qui tourne toujours en arriere plan
- {
- DateTime now = RTC.now();
- myGLCD.setFont(BigFont);
- if( now.hour() < 10)
- {
- myGLCD.print("0", 192, 2);
- myGLCD.print(String(now.hour()), 208, 2);
- myGLCD.print(":", 224, 2);
- }
- else
- {
- myGLCD.print(String(now.hour()), 192, 2);
- myGLCD.print(":", 224, 2);
- }
- if(now.minute() < 10)
- {
- myGLCD.print("0", 240, 2);
- myGLCD.print(String(now.minute()), 256, 2);
- myGLCD.print(":", 272, 2);
- }
- else
- {
- myGLCD.print(String(now.minute()), 240, 2);
- myGLCD.print(":", 272, 2);
- }
- if(now.second() <10)
- {
- myGLCD.print("0", 288, 2);
- myGLCD.print(String(now.second()), 304, 2);
- }
- else
- {
- myGLCD.print(String(now.second()), 288, 2);
- }
- delay(20);
- int HeureOn = int(EEPROMLecture(0));
- int HeureOff = int(EEPROMLecture(1));
- int MinuteOn = int(EEPROMLecture(2));
- int MinuteOff = int(EEPROMLecture(3));
- int VentilTempOn = int(EEPROMLecture(4));
- int VentilTempOff = int(EEPROMLecture(5));
- int VentilHumOn = int(EEPROMLecture(6));
- int VentilHumOff = int(EEPROMLecture(7));
- /*
- if( int(now.hour()) == HeureOn && int(now.minute()) == MinuteOn)
- {
- digitalWrite( PinRelai_1 , HIGH);
- EEPROMEcriture(1, 8);
- }
- if (int(now.hour()) == HeureOff && int(now.minute()) == MinuteOff)
- {
- digitalWrite( PinRelai_1 , LOW ) ;
- EEPROMEcriture(0, 8);
- }
- if( dht.readHumidity() < VentilHumOn )
- {
- digitalWrite( PinRelai_2 , HIGH ) ;
- EEPROMEcriture(1, 10) ;
- }
- else
- {
- digitalWrite( PinRelai_2 , LOW ) ;
- EEPROMEcriture(0, 10);
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement