Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #define PIN_NPN 2
- #define DEMIPERIODE_NPN 500
- #define PIN_PNP 3
- #define DEMIPERIODE_PNP 500
- #define NPN_IN 4
- #define PNP_IN 5
- #define NPN_WRONG 6
- #define PNP_WRONG 7
- #define VAL1 A0
- #define VAL2 A1
- #define VAL3 A2
- #define VAL4 A3
- #define VAL5 A4
- #define VAL6 A5
- #include<SPI.h> // introduction des librairties
- #include<Adafruit_GFX.h>
- #include<Adafruit_ILI9341.h>
- #include <SPFD5408_TouchScreen.h>
- #define TFT_DC 9 //definition des broches serie
- #define TFT_CS 10
- #define TFT_T_CS 7
- #define ILI9341_BLACK 0x0000 ///< 0, 0, 0 //definition des couleurs
- #define ILI9341_NAVY 0x000F ///< 0, 0, 123
- #define ILI9341_DARKGREEN 0x03E0 ///< 0, 125, 0
- #define ILI9341_DARKCYAN 0x03EF ///< 0, 125, 123
- #define ILI9341_MAROON 0x7800 ///< 123, 0, 0
- #define ILI9341_PURPLE 0x780F ///< 123, 0, 123
- #define ILI9341_OLIVE 0x7BE0 ///< 123, 125, 0
- #define ILI9341_LIGHTGREY 0xC618 ///< 198, 195, 198
- #define ILI9341_DARKGREY 0x7BEF ///< 123, 125, 123
- #define ILI9341_BLUE 0x001F ///< 0, 0, 255
- #define ILI9341_GREEN 0x07E0 ///< 0, 255, 0
- #define ILI9341_CYAN 0x07FF ///< 0, 255, 255
- #define ILI9341_RED 0xF800 ///< 255, 0, 0
- #define ILI9341_MAGENTA 0xF81F ///< 255, 0, 255
- #define ILI9341_YELLOW 0xFFE0 ///< 255, 255, 0
- #define ILI9341_WHITE 0xFFFF ///< 255, 255, 255
- #define ILI9341_ORANGE 0xFD20 ///< 255, 165, 0
- #define ILI9341_GREENYELLOW 0xAFE5 ///< 173, 255, 41
- #define ILI9341_PINK 0xFC18 ///< 255, 130, 198
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); // declarations
- enum affiche { VAL_TENSION1, VAL_TENSION2, VAL_TENSION3, VAL_TENSION4, VAL_TENSION5, VAL_TENSION6, TEMPO_NPN, TEMPO_PNP };
- struct strText{
- affiche id;
- String text;
- uint16_t color;
- uint16_t x;
- uint16_t y;
- uint8_t textSize;
- };
- //prototype des fonctions
- void initTft();
- void tftPrint(const uint16_t& color, const uint16_t& x, const uint16_t& y, const String text, const uint8_t& textSize = 2);
- void tftPrint(const strText& txt);
- void clearTxt(const strText& txt);
- void checkTension(const affiche& id,const float& tension, const int& seuil);
- //global variables
- int npn_in_haut = {0};
- int pnp_in_haut = {0};
- unsigned long temps_npn_in = {501};
- unsigned long temps_pnp_in = {501};
- unsigned long temps_actuel_npn{0};
- unsigned long temps_actuel_pnp{0};
- unsigned long temps_precedent_npn {0};
- unsigned long temps_precedent_pnp {0};
- uint16_t tftFondEcran {ILI9341_WHITE};
- bool printIsOK{false};
- strText text[6] {
- {VAL_TENSION1,"", ILI9341_RED, 80, 30, 2},
- {VAL_TENSION2,"", ILI9341_BLUE, 80, 60, 2},
- {VAL_TENSION3,"", ILI9341_GREEN, 80, 90, 2},
- {VAL_TENSION4,"", ILI9341_ORANGE, 80, 120, 2},
- {VAL_TENSION5,"", ILI9341_YELLOW, 80, 150, 2},
- {VAL_TENSION6,"", ILI9341_MAGENTA, 80, 180, 2}
- };
- strText textOkBad[8] {
- {VAL_TENSION1,"", ILI9341_RED, 80, 30, 2},
- {VAL_TENSION2,"", ILI9341_RED, 80, 60, 2},
- {VAL_TENSION3,"", ILI9341_RED, 80, 90, 2},
- {VAL_TENSION4,"", ILI9341_RED, 80, 120, 2},
- {VAL_TENSION5,"", ILI9341_RED, 80, 150, 2},
- {VAL_TENSION6,"", ILI9341_RED, 80, 180, 2},
- {TEMPO_NPN,"", ILI9341_RED, 168, 210, 2},
- {TEMPO_PNP,"", ILI9341_RED, 168, 240, 2}
- };
- const int textPrecedentSize {6};
- const int textOkBadPrecedentSize {8};
- strText textPrecedent[textPrecedentSize];
- strText textOkBadPrecedent[textOkBadPrecedentSize];
- const String textOK ="OK";
- const String textBad ="BAD";
- void setup() {
- pinMode(PIN_NPN, OUTPUT);
- pinMode(PIN_PNP, OUTPUT);
- pinMode (NPN_IN, INPUT);
- pinMode (NPN_WRONG, OUTPUT);
- pinMode (PNP_IN, INPUT);
- pinMode (PNP_WRONG, OUTPUT);
- pinMode (VAL1,INPUT);// entrée annalogique 0 +33.5v
- pinMode (VAL2,INPUT);// entrée annalogique 1 -33.5v
- pinMode (VAL3,INPUT);// entrée annalogique 2 11.5v
- pinMode (VAL4,INPUT);// entrée annalogique 3 25vac (13a/b)
- pinMode (VAL5,INPUT);// entrée annalogique 4 25vac (1a/b)
- pinMode (VAL6,INPUT);// entrée annalogique 5 17.5vac
- //atribution des entrées analogiques
- //-------------------------------------------------------------------------------------------
- //Serial.begin(9600);
- //delay(100);
- initTft();
- }
- //--------------------------------------------------------------------------------------------
- void loop() {
- // envoie des impultion vers transistors npn et pnp
- static unsigned long derniernpn = 0, dernierpnp = 0;
- if ((millis() - derniernpn) >= DEMIPERIODE_NPN) {
- derniernpn = derniernpn + DEMIPERIODE_NPN;
- digitalWrite (PIN_NPN, !digitalRead (PIN_NPN));
- }
- if ((millis() - dernierpnp) >= DEMIPERIODE_PNP) {
- dernierpnp = dernierpnp + DEMIPERIODE_PNP;
- digitalWrite (PIN_PNP, !digitalRead (PIN_PNP));
- }
- // verification de la tempo npn.
- temps_actuel_npn = millis ();
- if ( !digitalRead(NPN_IN) ) { //LOW
- if ( temps_actuel_npn < temps_npn_in ){
- textOkBad[TEMPO_NPN].text = textBad;
- }
- else {
- temps_precedent_npn = temps_actuel_npn;
- textOkBad[TEMPO_NPN].text = textOK;
- }
- tftPrint(textOkBad[TEMPO_NPN]);
- }
- else if ( (temps_actuel_npn - temps_precedent_npn > temps_npn_in)){
- //digitalWrite (NPN_WRONG, HIGH);
- textOkBad[TEMPO_NPN].text = textBad;
- tftPrint(textOkBad[TEMPO_NPN]);
- }
- // verification de la tempo pnp.
- temps_actuel_pnp = millis ();
- // pnp_in_haut = digitalRead (PNP_IN);
- if (!digitalRead(PNP_IN)){ //LOW
- if ( temps_actuel_pnp < temps_pnp_in ){
- textOkBad[TEMPO_PNP].text = textBad;
- }
- else{
- temps_precedent_pnp = temps_actuel_pnp;
- textOkBad[TEMPO_PNP].text = textOK;
- }
- tftPrint(textOkBad[TEMPO_PNP]);
- }
- else if ( (temps_actuel_pnp - temps_precedent_pnp > temps_pnp_in)){
- textOkBad[TEMPO_PNP].text = textBad;
- tftPrint(textOkBad[TEMPO_PNP]);
- }
- //---------------LECTURE DES TENSIONS MAINFRAME-----------------
- float tension1 = analogRead(VAL1);// Lire la valeur analogique +33.5v
- // Diviser par 205 puis multiplié par 7.976-
- //-pour convertir 4.2V encodés sur 10 bits
- //(1024 valeurs: 1024/5=243.8095*7.976 == valeure réel)
- float tension_a = tension1 / 204.8f * 7.976f ;
- text[VAL_TENSION1].text = String(tension_a, 2);
- tftPrint(text[VAL_TENSION1]);
- //verifie la condition de tension +33.5v
- //si tension inferieur a 28v = bad en rouge
- // sinon ok en vert
- checkTension(VAL_TENSION1,tension_a,28);
- //lecture tension -33.5v
- float tension2 = analogRead(VAL2);// Lire la valeur analogique -33.5v
- // Diviser par 205 puis multiplié par 7.976-
- //-pour convertir 4.2V encodés sur 10 bits
- //(1024 valeurs: 1024/5=243.8095*7.976 == valeure réel)
- float tension_b = tension2 / 204.8f * 7.976f ;
- //affichage des valeurs sur ecran tft ILI9341
- text[VAL_TENSION2].text = String(tension_b, 2);
- tftPrint(text[VAL_TENSION2]);
- //verifie la condition de tension -33.5v
- //si tension inferieur a 28v = bad en rouge
- // sinon ok en vert
- checkTension(VAL_TENSION2,tension_b,28);
- float tension3 = analogRead(VAL3);// Lire la valeur analogique 11.5v
- // Diviser par 205 puis multiplié par 5.952-
- //-pour convertir 4.2V encodés sur 10 bits
- //(1024 valeurs: 1024/5=204.8*5.952 == valeure réel)
- float tension_c = tension3 /243.8095f * 5.952f ;
- //affichage des valeurs sur ecran tft ILI9341
- text[VAL_TENSION3].text = String(tension_c, 2);
- tftPrint(text[VAL_TENSION3]);
- //verifie la condition de tension 25vac
- //si tension inferieur a 20vac = bad en rouge
- // sinon ok en vert
- checkTension(VAL_TENSION3,tension_c,20);
- // Lire la valeur analogique
- float tension4 = analogRead(VAL4);
- // Diviser par 205 puis multiplié par 5.952-
- //-pour convertir 4.2V encodés sur 10 bits
- //(1024 valeurs: 1024/5=204.8*5.952 == valeure réel)
- float tension_d = tension4 / 243.8095f *5.952f ;
- //affichage des valeurs sur ecran tft ILI9341
- text[VAL_TENSION4].text = String(tension_d, 2);
- tftPrint(text[VAL_TENSION4]);
- checkTension(VAL_TENSION4,tension_d,20);
- // Lire la valeur analogique
- float tension5 = analogRead(VAL5);
- // Diviser par 205 puis multiplié par 4.1666-
- //-pour convertir 4.2V encodés sur 10 bits
- //(1024 valeurs: 1024/5=204.8*4.1666 == valeure réel)
- float tension_e = tension5 / 204.8f *4.1666f ;
- //affichage des valeurs sur ecran tft ILI9341
- text[VAL_TENSION5].text = String(tension_e, 2);
- tftPrint(text[VAL_TENSION5]);
- //verifie la condition de tension 17.5vac
- //si tension inferieur a 13vac = bad en rouge
- // sinon ok en vert
- checkTension(VAL_TENSION5,tension_e,13);
- // Lire la valeur analogique
- float tension6 = analogRead(VAL6);
- // Diviser par 205 puis multiplié par 2.738-
- //-pour convertir 4.2V encodés sur 10 bits
- //(1024 valeurs: 1024/5=243.8095*2.738 == valeure réel)
- float tension_f = tension6 / 204.8f * 2.738f ;
- //affichage des valeurs sur ecran tft ILI9341
- text[VAL_TENSION6].text = String(tension_f, 2);
- tftPrint(text[VAL_TENSION6]);
- //verifie la condition de tension 11.5vdc
- //si tension inferieur a 9vdc= bad en rouge
- // sinon ok en vert
- checkTension(VAL_TENSION6,tension_f,9);
- }
- void initTft() {
- //TEXTES STATIQUE ET TENSIONS NOMINALES.
- tft.begin();
- tft.setSPISpeed(8000000); // vitesse de la liaison serie
- delay(100);
- tft.setRotation(0); //POSTION DE L'ECRAN
- tft.fillScreen(tftFondEcran); //couleur fond d'ecran
- tft.setTextColor(ILI9341_BLACK); //taille, couleur, et position de "nomine"
- tft.setTextSize(2);
- tft.setCursor(2,2);
- tft.println("NOMIN");
- tft.setCursor(80,2); //taille, couleur position et de "measur"
- tft.println("MEASUR");
- tft.setCursor(168,2); //taille, et position de "status"
- tft.println("STATUS");
- tft.setTextColor(ILI9341_RED); //taille, couleur et position des differentes tensions nominal
- tft.setCursor(2,30);
- tft.println("+33.5");
- tft.setTextColor(ILI9341_BLUE);
- tft.setCursor(2,60);
- tft.println("-33.5");
- tft.setTextColor(ILI9341_GREEN);
- tft.setCursor(2,90);
- tft.println("11.5DC");
- tft.setTextColor(ILI9341_ORANGE);
- tft.setCursor(2,120);
- tft.println("25AC");
- tft.setTextColor(ILI9341_YELLOW);
- tft.setCursor(2,150);
- tft.println("25AC");
- tft.setTextColor(ILI9341_MAGENTA);
- tft.setCursor(2,180);
- tft.println("17.5AC");
- tft.setTextColor(ILI9341_BLUE); //taille, couleur et position de "npn"
- tft.setCursor(2,210);
- tft.println("NPN");
- tft.setTextColor(ILI9341_RED); //taille, couleur et position de "pnp"
- tft.setCursor(2,240);
- tft.println("PNP");
- tft.fillRect(85,293,57,15,(ILI9341_PINK));//taille, couleur, encadré et position de "MT501"
- tft.setTextColor(ILI9341_BLACK);
- tft.setCursor(85,293);
- tft.println("MT501");
- tft.setTextColor(ILI9341_BLACK); //taille, couleur et position de "SN/TL020MT"
- tft.setCursor(2,300);
- tft.setTextSize(1);
- tft.println("S/N TL-020MT");
- //-------------------------------------------------------------------------------------------
- //CREATION DU LOGO "INT"
- tft.fillRect(160,280,8,45,(ILI9341_GREEN)); // barres verticales
- tft.fillRect(168,280,8,45,(ILI9341_GREEN));
- tft.fillRect(193,280,8,45,(ILI9341_GREEN));
- tft.fillRect(201,280,8,45,(ILI9341_GREEN));
- tft.fillRect(209,280,8,8,(ILI9341_GREEN)); //trait horizontale du "T"
- tft.fillCircle(164,276,4,(ILI9341_BLUE)); //point bleu
- tft.drawLine(193,320,176,290,(ILI9341_GREEN)); // barre oblique
- tft.drawLine(193,319,176,289,(ILI9341_GREEN));
- tft.drawLine(193,318,176,288,(ILI9341_GREEN));
- tft.drawLine(193,317,176,287,(ILI9341_GREEN));
- tft.drawLine(193,316,176,286,(ILI9341_GREEN));
- tft.drawLine(193,315,176,285,(ILI9341_GREEN));
- tft.drawLine(193,324,176,284,(ILI9341_GREEN));
- tft.drawLine(193,313,176,283,(ILI9341_GREEN));
- //--------------------------------------------------------------------------------------------
- //LIGNES DE SEPARATION.
- tft.drawFastVLine(75,0,258,(ILI9341_BLACK)); // lignes de separation verticales
- tft.drawFastVLine(163,0,258,(ILI9341_BLACK));
- tft.drawFastHLine(0,20,240,(ILI9341_BLACK)); // lignes de separation horizontales
- tft.drawFastHLine(0,258,240,(ILI9341_BLACK));
- tft.drawFastHLine(0,200,240,(ILI9341_BLACK));
- }
- void tftPrint(const uint16_t& color, const uint16_t& x, const uint16_t& y, const String text, const uint8_t& textSize) {
- tft.setTextSize(textSize);
- tft.setTextColor(color);
- tft.setCursor(x,y);
- tft.println(text);
- }
- void tftPrint(const strText& txt){
- if(txt.id == TEMPO_NPN || txt.id == TEMPO_PNP){
- int pos=0;
- for(int i = 0 ; i < textOkBadPrecedentSize ; i++){
- if(textOkBadPrecedent[i].id == txt.id){
- pos = i;
- break;
- }
- }
- if(txt.text != textOkBadPrecedent[pos].text ){
- clearTxt(textOkBadPrecedent[pos]);
- textOkBadPrecedent[pos] = txt;
- tftPrint(txt.color,txt.x,txt.y,txt.text,txt.textSize);
- }
- }
- else{
- int pos=0;
- for(int i = 0 ; i < textPrecedentSize ; i++){
- if(textPrecedent[i].id == txt.id){
- pos = i;
- break;
- }
- }
- if(txt.text != textPrecedent[pos].text ){
- clearTxt(textPrecedent[pos]);
- textPrecedent[pos] = txt;
- tftPrint(txt.color,txt.x,txt.y,txt.text,txt.textSize);
- }
- }
- }
- void clearTxt(const strText& txt){
- tft.setTextSize(txt.textSize);
- tft.setTextColor(tftFondEcran); //taille, couleur et position de "npn"
- tft.setCursor(txt.x,txt.y);
- tft.println(txt.text);
- }
- void checkTension(const affiche& id,const float& tension, const int& seuil){
- if (tension < seuil) textOkBad[id].text = textBad;
- else textOkBad[id].text = textOK;
- tftPrint(textOkBad[id]);
- }
Advertisement
Add Comment
Please, Sign In to add comment