Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //************************************************ ************************************************
- //************************************************ ************************************************
- //************************************** declaration ******************************************
- //************************************************ ************************************************
- //************************************************ ************************************************
- #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>
- #include <PinChangeInt.h>
- unsigned int selecteurPage = 0; //variable de sélection de menu pour l'interface tactile
- boolean comptAff = false; // compteur d'affichage permet de ne pas rafraichir en permanence
- RTC_DS1307 RTC ;
- #define DHTPIN 19 // what pin we're connected to
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- DHT dht(DHTPIN, DHTTYPE);
- UTFT myGLCD(SSD1289, 38, 39, 40, 41);
- UTouch myTouch( 6, 5, 4, 3, 2);
- UTFT_Buttons myButtons(&myGLCD, &myTouch);
- extern uint8_t SmallFont[];
- extern uint8_t BigFont[];
- extern uint8_t SevenSegNumFont[];
- #define SET A8
- #define GAUCHE A9
- #define BAS A10
- #define DROITE A11
- #define HAUT A12
- int ComptButtonYmax = 4 ;
- int ComptButtonX = 0;
- int ComptButtonY = 0;
- boolean setbutton = false;
- int comptButton = 0 ;
- int PinRelaisLight = 8;
- int PinRelaisFan = 9;
- int PinRelais_1 = 10;
- #if defined(__AVR__)
- #define imagedatatype unsigned int
- #elif defined(__PIC32MX__)
- #define imagedatatype unsigned short
- #elif defined(__arm__)
- #define imagedatatype unsigned short
- #endif
- extern imagedatatype LogoLum[];
- extern imagedatatype LogoValider[];
- extern imagedatatype LogoVentil[];
- extern unsigned int Logo[0x3840];
- extern unsigned int LogoLum[0x640];
- extern unsigned int LogoRetour[0x640];
- extern unsigned int LogoValider[0x640];
- extern unsigned int LogoVentil[0x640];
- //************************************************ ************************************************
- //************************************************ ************************************************
- //************************************* Fonctions principales *****************************************
- //************************************************ ************************************************
- //************************************************ ************************************************
- void setup()
- {
- Serial.println("setup");
- Serial.begin(9600);
- initialisationPin() ;
- initialisationBus() ;
- initialisationScreen() ;
- initialisationRelais () ;
- }
- void loop()
- {
- //Serial.println("loop");
- switch (selecteurPage)
- {
- case 0:
- MenuPrincipal() ;
- break;
- case 1:
- MenuLight() ;
- break;
- case 2:
- MenuFan() ;
- break;
- case 3:
- MenuIntraExtra() ;
- break;
- case 4:
- MenuSetting() ;
- break;
- default :
- MenuPrincipal();
- break;
- }
- }
- //************************************************ ************************************************
- //************************************************ ************************************************
- //***************************************** initialisation ********************************************
- //************************************************ ************************************************
- //************************************************ ************************************************
- void initialisationBus()
- {
- Serial.println("initialisationBus");
- Wire.begin(19);
- RTC.begin();
- dht.begin();
- delay(20);
- }
- void initialisationScreen()
- {
- Serial.println("initialisationScreen");
- //myTouch.setPrecision(PREC_LOW);
- myTouch.InitTouch();
- myGLCD.InitLCD();
- delay(20);
- myGLCD.clrScr();
- delay(20);
- myGLCD.fillScr(0, 102, 51);
- //myGLCD.drawBitmap (100, 50, 120, 120, Logo, 1);
- delay(20);
- myGLCD.setFont(SmallFont);
- myGLCD.setBackColor(0, 102, 51);
- myGLCD.setColor(10, 50, 30);
- myGLCD.print("- INITIALISATION -", CENTER, 195);
- myGLCD.print("TACTILE", CENTER, 205);
- myGLCD.print("I2C", CENTER, 215);
- }
- void initialisationPin()
- {
- Serial.println("initialisationPin");
- pinMode(HAUT, INPUT_PULLUP);
- pinMode(BAS, INPUT_PULLUP);
- pinMode(GAUCHE, INPUT_PULLUP);
- pinMode(DROITE, INPUT_PULLUP);
- pinMode(SET, INPUT_PULLUP);
- attachPinChangeInterrupt(HAUT, haut, FALLING);
- attachPinChangeInterrupt(BAS, bas, FALLING);
- attachPinChangeInterrupt(GAUCHE, gauche, FALLING);
- attachPinChangeInterrupt(DROITE, droite, FALLING);
- attachPinChangeInterrupt(SET, set, FALLING);
- pinMode( PinRelaisLight, OUTPUT);
- pinMode( PinRelaisFan, OUTPUT);
- pinMode( PinRelais_1, OUTPUT);
- }
- void initialisationRelais()
- {
- Serial.println("initialisationRelais");
- /*
- if(EEPROMLecture(8) == 1)
- {
- digitalWrite(RelaisLight, HIGH);
- }
- else
- {
- digitalWrite(RelaisLight, LOW);
- }
- if(EEPROMLecture(9) == 1)
- {
- digitalWrite(RelaisFan, HIGH);
- }
- else
- {
- digitalWrite(RelaisFan, LOW);
- }
- if(EEPROMLecture(10) == 1)
- {
- digitalWrite(Relais_1, HIGH);
- }
- else
- {
- digitalWrite(Relais_1, LOW);
- }
- */
- delay(20);
- }
- //************************************************ ************************************************
- //************************************************ ************************************************
- //**************************************** Fonctions pages ********************************************
- //************************************************ ************************************************
- //************************************************ ************************************************
- void MenuPrincipal()
- {
- //Serial.println("MenuPrincipal");
- switch (comptAff)
- {
- case 0:
- // Ici on trace, affiche, ce que l'on veut:
- /// Exemple les zone de nos touches
- 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( "bouton" ) ;
- Serial.println(String( ComptButtonY )) ;
- iconLum = myButtons.addButton( 2 , 197 , 40 , 40 , LogoLum ) ;
- iconRelais_1 = myButtons.addButton( 44 , 197 , 40 , 40 , LogoVentil ) ;
- iconRelais_2 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoVentil ) ;
- //iconRelais_3 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoIntraExtra ) ;
- iconSetting = myButtons.addButton( 128 , 197 , 40 , 40 , LogoVentil ) ;
- myButtons.drawButtons();
- myGLCD.setFont(SmallFont);
- comptAff = true; // on passe la variable d'affichage a vrai pour qu'au prochain cycle cette partie du code ne soit pas réécrite
- break;
- case 1:
- // Ici on affichera no variable :
- // Exemple l'heure
- // On test s'il y a appuis sur la zone situer au pixel 100,100 //de longueur 50pixel et de hauteur 30pixel
- if (TestTouche( 2, 197, 40, 40) or checkButton() )
- {
- selecteurPage = 1; // on sélectionne la nouvelle page a aficher
- comptAff = false; // on oublie pas de réinitialiser notre variable d'affichage
- return;
- }
- // on test s'il y a appuis sur la zone situer au pixel 200,200 //de longueur 50pixel et de hauteur 30pixel
- if (TestTouche( 44, 197, 40, 40) == true )
- {
- selecteurPage = 2; // on sélectionne la nouvelle page a afficher
- comptAff = false;
- return;
- }
- // On test s'il y a appuis sur la zone situer au pixel 100,100 //de longueur 50pixel et de hauteur 30pixel
- if (TestTouche( 86, 197, 40, 40) == true )
- {
- selecteurPage = 3; // on sélectionne la nouvelle page a aficher
- comptAff = false; // on oublie pas de réinitialiser notre variable d'affichage
- return;
- }
- // on test s'il y a appuis sur la zone situer au pixel 200,200 //de longueur 50pixel et de hauteur 30pixel
- if (TestTouche( 128, 197, 40, 40) == true )
- {
- selecteurPage = 4; // on sélectionne la nouvelle page a afficher
- comptAff = false;
- return;
- }
- break;
- }
- return;
- /*
- Ymax = 4;
- X=0;
- Y=0;
- 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 ;
- iconLum = myButtons.addButton( 2 , 197 , 40 , 40 , LogoLum ) ;
- iconRelais_1 = myButtons.addButton( 44 , 197 , 40 , 40 , LogoVentil ) ;
- iconRelais_2 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoVentil ) ;
- //iconRelais_3 = myButtons.addButton( 86 , 197 , 40 , 40 , LogoIntraExtra ) ;
- iconSetting = myButtons.addButton( 128 , 197 , 40 , 40 , LogoVentil ) ;
- myButtons.drawButtons();
- myGLCD.setFont(SmallFont);
- while(1)
- {
- //Continue() ;
- //Serial.println("Continue");
- }
- */
- }
- bool checkButton( )
- {
- Serial.println("checkButton");
- Serial.println(String(ComptButtonY));
- if ( ComptButtonY == 0 )
- {
- Serial.println("inBoucle0");
- //myGLCD.clrScr();
- //TracerCadre(52, 193, 40, 40, 0 ,102, 51);
- myGLCD.setFont(SmallFont);
- myGLCD.setColor(0,0,0);
- myGLCD.print("Lumiere", 4, 4);
- TracerCadre(4 ,195, 40, 40, 255, 0, 0);
- if( setbutton == true )
- {
- setbutton = false;
- return true ;
- }
- }
- else if ( ComptButtonY == 1 )
- {
- Serial.println("inBoucle1");
- //myGLCD.clrScr();
- TracerCadre(4, 193, 40, 40, 0 ,102, 51);
- delay(200);
- myGLCD.setFont(SmallFont);
- myGLCD.setColor(0,0,0);
- myGLCD.print("fanbox", 4, 4);
- TracerCadre(52 ,193, 40, 40, 255, 0, 0);
- if(setbutton == true)
- {
- setbutton = false;
- return true ;
- }
- }
- else if ( ComptButtonY == 2 )
- {
- Serial.println("inBoucle2");
- //myGLCD.clrScr();
- TracerCadre(52, 193, 40, 40, 0 ,102, 51);
- delay(200);
- myGLCD.setFont(SmallFont);
- myGLCD.setColor(0,0,0);
- myGLCD.print("relai3", 4, 4);
- TracerCadre(90 ,193, 40, 40, 255, 0, 0);
- if(setbutton == true)
- {
- setbutton = false;
- return true ;
- }
- }
- else if ( ComptButtonY == 3 )
- {
- Serial.println("inBoucle3");
- //myGLCD.clrScr();
- TracerCadre(90, 193, 40, 40, 0 ,102, 51);
- delay(200);
- myGLCD.setFont(SmallFont);
- myGLCD.setColor(0,0,0);
- myGLCD.print("relai4", 4, 4);
- TracerCadre(130 ,193, 40, 40, 255, 0, 0);
- if(setbutton == true)
- {
- setbutton = false;
- return true ;
- }
- }
- return false ;
- }
- void MenuLight()
- {
- Serial.println("MenuLight");
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- myGLCD.fillScr(0, 255, 0);
- }
- void MenuFan()
- {
- Serial.println("MenuFan");
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- myGLCD.fillScr(255, 0, 0);
- }
- void MenuIntraExtra()
- {
- Serial.println("MenuIntraExtra");
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- myGLCD.fillScr(0, 0, 255);
- }
- void MenuSetting()
- {
- Serial.println("MenuSetting");
- myGLCD.clrScr();
- myButtons.deleteAllButtons();
- myGLCD.fillScr(255, 255, 0);
- }
- void Continue() //focntion qui tourne toujours en arriere plan
- {
- DateTime now = RTC.now();
- if (int(now.second()) == 30)
- {
- if (int(now.minute()) == 1 || int(now.minute()) == 15 || int(now.minute()) == 30 || int(now.minute()) == 45)
- //if((int(now.minute()) % 2) ==0)
- {
- //MemoireGraph();
- delay(960);
- }
- }
- myGLCD.setColor(0, 0, 0);
- 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(RelaiLampe, HIGH);
- EEPROMEcriture(1, 8);
- }
- if (int(now.hour()) == HeureOff && int(now.minute()) == MinuteOff)
- {
- digitalWrite(RelaiLampe, LOW);
- EEPROMEcriture(0, 8);
- }
- if(dht.readHumidity() < VentilHumOn)
- {
- digitalWrite(RelaiVapo, HIGH);
- EEPROMEcriture(1, 10);
- }
- else
- {
- digitalWrite(RelaiVapo, LOW);
- EEPROMEcriture(0, 10);
- }
- */
- }
- //************************************************ ************************************************
- //************************************************ ************************************************
- //************************************** Fonctions graphique ******************************************
- //************************************************ ************************************************
- //************************************************ ************************************************
- void TracerCadre(int xpos, int ypos, int xlong, int ylong, int R, int G, int B)
- {
- myGLCD.setColor(R, G, B);
- myGLCD.drawRect(xpos - 1, ypos - 1, xpos + xlong + 1, ypos + ylong + 1);
- myGLCD.drawRect(xpos - 2, ypos - 2, xpos + xlong + 2, ypos + ylong + 2);
- myGLCD.drawRect(xpos - 3, ypos - 3, xpos + xlong + 3, ypos + ylong + 3);
- myGLCD.drawRect(xpos - 4, ypos - 4, xpos + xlong + 4, ypos + ylong + 4);
- }
- void TracerTriHaut(int xpos, int ypos, int R, int G, int B)
- {
- for (int y = 0 ; y < 17; y++)
- {
- for (int x = 0 ; x < 15 ; x++)
- {
- myGLCD.setColor(R, G, B);
- myGLCD.drawLine(xpos + y - 1, ypos - y, xpos + 32 - y, ypos - y);
- }
- }
- }
- void TracerTriBas(int xpos, int ypos, int R, int G, int B)
- {
- for (int y = 0 ; y < 17; y++)
- {
- for (int x = 0 ; x < 15 ; x++)
- {
- myGLCD.setColor(R, G, B);
- myGLCD.drawLine(xpos + y - 1, ypos + y, xpos + 32 - y, ypos + y);
- }
- }
- }
- //************************************************ ************************************************
- //************************************************ ************************************************
- //************************************** Fonctions tactile ******************************************
- //************************************************ ************************************************
- //************************************************ ************************************************
- boolean TestTouche( int zoneX, int zoneY, int Longueur, int hauteur)
- {
- Serial.println( "TestTouche" );
- delay(500);
- int X, Y, testX, testY; // varriable
- if ( myTouch.dataAvailable() )// dataAvailable() est une fonction de la lib Utouch.h
- {
- myTouch.read();// read() est une fonction de la lib Utouch.h
- X = myTouch.getX();
- Y = myTouch.getY(); // getX et getY() sont des fonction de la lib Utouch.h
- Serial.println( String( X ) );
- //---- vérifie si appui sur la touche "+" ---------
- testX = abs(X - (zoneX + Longueur / 2)); // calcul valeur absolue de l'écart de X touchpad à la Zone X centre touche
- testY = abs(Y - (zoneY + hauteur / 2)); // calcul valeur absolue de l'écart de Y touchpad à la Zone Y centre touche
- if (testX < Longueur / 2 && testY < hauteur / 2)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- return false;
- }
- //************************************************ ************************************************
- //************************************************ ************************************************
- //************************************** Fonctions joystique ******************************************
- //************************************************ ************************************************
- //************************************************ ************************************************
- //************************************** HAUT ****************************************************
- void haut()
- {
- Serial.println("haut");
- delay(200);
- ComptButtonX++;
- //Serial.print("Haut");
- }
- //************************************** BAS ****************************************************
- void bas()
- {
- Serial.println("bas");
- delay(200);
- ComptButtonX--;
- }
- //************************************** GAUCHE ****************************************************
- void gauche()
- {
- Serial.println("gauche");
- Serial.println(String(ComptButtonY));
- delay(200);
- if ( ComptButtonY > 0)
- {
- ComptButtonY--;
- }
- }
- //************************************** DROITE ****************************************************
- void droite()
- {
- Serial.println("droite");
- Serial.println(String(ComptButtonY));
- if ( ComptButtonY < ComptButtonYmax )
- {
- delay(200);
- ComptButtonY++;
- }
- }
- //************************************** SET ****************************************************
- void set()
- {
- Serial.println("set");
- if (setbutton == false)
- {
- setbutton = true ;
- Serial.println("true");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement