#include "MCUFRIEND_kbv.h" MCUFRIEND_kbv tft; #define LOWFLASH (defined(__AVR_ATmega328P__) && defined(MCUFRIEND_KBV_H_)) #include "bitmap_mono.h" #include "bitmap_RGB.h" //http://www.barth-dev.de/online/rgb565-color-picker/ #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define GREY 0x8410 #define ORANGE 0xE880 #define LTGRAY 0xC618 #define LTRED 0xFC10 #define LTBLUE 0x841F #define DKGREEN 0x0600 #define DKRED 0xC000 #define DKBLUE 0x0018 #define ZEROCLR 0xFE10 #define TEAL 0x0410 void setup() { //Serial.begin(9600); uint16_t ID = tft.readID(); //Serial.print(F("ID = 0x")); //Serial.println(ID, HEX); tft.begin(ID); tft.invertDisplay(1); tft.setRotation(1); tft.fillScreen(TEAL); } void loop(void) { String serialStruct = "m08d12h12m34Tank.00-10990070780102030405060708091011121314151617181920212378602322212019181716151413121110090807060504030278Shed!44 0 110-1780102030405060708091011121314151617181920212378502322212019181716151413121110090807060504030278Park.01 88100110780102030405060708091011121314151617181920212378402322212019181716151413121110090807060504030278Dorm.22 -2 91140780102030405060708091011121314151617181920212378302322212019181716151413121110090807060504030278"; char dateTime[13]; serialStruct.toCharArray(dateTime, 13); tft.setTextSize(3); tft.fillRect(460, 0, 20, 320, BLACK); for (int dt = 0; dt <= 11; dt++) { if (isAlpha(dateTime[dt])) { tft.setTextColor(DKGREEN, BLACK); } else { tft.setTextColor(GREEN, BLACK); } tft.setCursor(462, dt * 24 - 5); tft.print(dateTime[dt]); } tft.fillRect(462, 286, 15, 34, DKGREEN); tft.fillRect(464, 288, 11, 30, BLACK); // x = # de l'esp, represente la ligne 0 = tank, 1 = shed, 2 = Park, 3 = Dorm (fini par . ou ! pour afficher en rouge ou vert si bonne lecture de la station) // ESPName = nom de l'esp : tank, shed ... // foreCast = # de l'image a afficher : cloudy, rain... // tendencty = fleche qui represente la tendenace du forecase : arrowRaise, arrowUp... // temeperature = char[3] qui represente la temperature: " -3", " 2", "-15" (brrr) // humidity = char[2] qui represente l'humidite % : " 1", "66" // tempDir = fleche qui represente si la temperature monte ou descend: 0=arrowUp, 1=arrowDown, 2=rien (RED) // tempDir = fleche qui represente si l'humidite monte ou descend: 0=arrowUp, 1=arrowDown, 2=rien (BLUE) // zeroValue = value du zero, zero = 0-77, si zero = -1 alors pas sur le gfx // tem[24] = domaine temperature : 0-78 // hum[24] = domaine humidite : 0-78 int baseStr = 12; int dataLenght = 112; for (int station = 0; station <= 4; station++) { drawLine(station, serialStruct.substring(baseStr + dataLenght * station, baseStr + dataLenght * station + 112)); } //drawLine(0, "Tank.00-10990070780102030405060708091011121314151617181920212378602322212019181716151413121110090807060504030278"); //drawLine(1, "Shed!44 0 110-1780102030405060708091011121314151617181920212378502322212019181716151413121110090807060504030278"); //drawLine(2, "Park.01 88100110780102030405060708091011121314151617181920212378402322212019181716151413121110090807060504030278"); //drawLine(3, "Dorm.22 -2 91140780102030405060708091011121314151617181920212378302322212019181716151413121110090807060504030278"); for (int timeOut = 0; timeOut <= 30; timeOut ++) { delay (50); tft.drawLine(464, 317 - timeOut, 474, 317 - timeOut, GREEN); } } // dessiner un carrer d'info pour les 4 //void drawLine(int x, char ESPName[4], int foreCast, int tendency, char temperature[3], char humidity[2], int tempDir, int humDir, String strZero, int tem[], int hum[]) void drawLine(int x, String dataStruct) { String ESPName; int foreCast; int tendency; String temperature; String humidity; int tempDir; int humDir; int zero; int tem[24]; int hum[24]; ESPName = dataStruct.substring(0, 5); foreCast = dataStruct.substring(5, 6).toInt(); tendency = dataStruct.substring(6, 7).toInt(); temperature = dataStruct.substring(7, 10); humidity = dataStruct.substring(10, 12); tempDir = dataStruct.substring(12, 13).toInt(); humDir = dataStruct.substring(13, 14).toInt(); zero = dataStruct.substring(14, 16).toInt(); for (int ihrs = 0; ihrs < 24; ihrs++) { tem[ihrs] = dataStruct.substring(16 + ihrs * 2, 16 + ihrs * 2 + 2).toInt(); } for (int ihrs = 0; ihrs < 24; ihrs++) { hum[ihrs] = dataStruct.substring(64 + ihrs * 2, 64 + ihrs * 2 + 2).toInt(); } // *** DRAW GUI and esp NAME tft.fillRect(1, x * 80 + 1, 458, 78, BLACK); tft.setTextSize(3); tft.drawRect(0, x * 80, 460, 80, GREY); tft.setTextColor(RED, BLACK); if (ESPName[4] == '.') tft.setTextColor(GREEN, BLACK); ESPName[4] = '\0'; //enlever le caractere de status du nom de l'esp tft.setCursor(2, x * 80 + 2); tft.print(ESPName); // *** DRAW FORCAST bitmap if (foreCast == 0) tft.drawRGBBitmap(2, 30 + x * 80, cloudy, 48, 48); if (foreCast == 1) tft.drawRGBBitmap(2, 30 + x * 80, rain, 48, 48); if (foreCast == 2) tft.drawRGBBitmap(2, 30 + x * 80, storm, 48, 48); if (foreCast == 3) tft.drawRGBBitmap(2, 30 + x * 80, sun, 48, 48); if (foreCast == 4) tft.drawRGBBitmap(2, 30 + x * 80, unstable, 48, 48); // *** DRAW Forecast tendency arrow if (tendency == 0) tft.drawBitmap(49, 54 + x * 80, arrowDown, 24, 24, WHITE); if (tendency == 1) tft.drawBitmap(49, 54 + x * 80, arrowFall, 24, 24, LTGRAY); if (tendency == 2) tft.drawBitmap(49, 54 + x * 80, arrowStable, 24, 24, LTGRAY); if (tendency == 3) tft.drawBitmap(49, 54 + x * 80, arrowRaise, 24, 24, LTGRAY); if (tendency == 4) tft.drawBitmap(49, 54 + x * 80, arrowUp, 24, 24, WHITE); // *** Draw actual temperature and humidity + last value change arrow tft.setTextSize(5); tft.setTextColor(LTRED, BLACK); tft.setCursor(72, x * 80 + 2); tft.print(temperature); tft.setTextColor(LTBLUE, BLACK); tft.setCursor(283, x * 80 + 2); tft.print(humidity); if (tempDir == 0) tft.drawBitmap(135, 54 + x * 80, arrowUp, 24, 24, DKRED); if (tempDir == 1) tft.drawBitmap(135, 54 + x * 80, arrowDown, 24, 24, DKRED); if (humDir == 0) tft.drawBitmap(316, 54 + x * 80, arrowUp, 24, 24, DKBLUE); if (humDir == 1) tft.drawBitmap(316, 54 + x * 80, arrowDown, 24, 24, DKBLUE); // *** DRAW temperature & humidity GRAPH for (int ihrs = 0; ihrs < 24; ihrs++) { tft.fillRect(158 + ihrs * 5, x * 80 + 79, 5, -tem[ihrs], RED); tft.fillRect(339 + ihrs * 5, x * 80 + 79, 5, -hum[ihrs], BLUE); } //*** DRAW zero line, -1 = zero is not on graph if (zero != -1) { for (int ihrs = 0; ihrs <= 118; ihrs = ihrs + 2) { tft.drawPixel(ihrs + 158, x * 80 + 78 - zero, ZEROCLR); } } }