#include #include #include #include #include #include #include #include #include extern uint8_t WeatherFont72x72[]; // weather icons extern uint8_t MyriadProCond2bpp20[]; // min/max labels extern uint8_t MyriadProCond2bpp24[]; // date, pressure label extern uint8_t MyriadProCond2bpp48[]; // temp labels extern uint8_t YuGoticNumeric2bpp68[]; // clock const int COLOR_BG = 0xffec;//RGB16(0xe7, 0xdf, 0xd0); const int COLOR_FG = RGB16(0x00, 0x00, 0x00); char *months[] = {"������", "�������", "�����", "������", "���", "����", "����", "�������", "��������", "�������", "������", "�������"}; char *weekdays[] = {"�����������", "�������", "�����", "�������", "�������", "�������", "�����������"}; const int BAR_WIDTH = 240; const int BAR_HEIGHT = 50; const int BAR_BORDER_MARGIN = 2; const int BAR_LEFT = 10; const int T_IN_BAR_TOP = 275; const int T_OUT_BAR_TOP = 345; const int PRESSURE_BAR_TOP = 415; MyTFT myGLCD(HX8357B, 38,39,40,41); Adafruit_BMP085 bmp; DS3231 rtc(SDA, SCL); RF24 radio(9,10); RF24Network network(radio); uint16_t rf24_channel = 111; uint16_t rf24_master_node_address = 0; Label lblDate(&myGLCD, 160, 10, MyriadProCond2bpp24, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); Label lblClock(&myGLCD, 20, 65, YuGoticNumeric2bpp68, COLOR_FG, COLOR_BG, ALIGN_LEFT, ALIGN_TOP); Label lblPressureIcon(&myGLCD, 270, 55, WeatherFont72x72, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); Label lblPressureValue(&myGLCD, 270, 130, MyriadProCond2bpp24, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); Label lblTempInValue(&myGLCD, 70, 175, MyriadProCond2bpp48, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); Label lblTempInText(&myGLCD, 70, 220, MyriadProCond2bpp24, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); Label lblTempOutValue(&myGLCD, 210, 175, MyriadProCond2bpp48, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); Label lblTempOutText(&myGLCD, 210, 220, MyriadProCond2bpp24, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); Label lblTempInMax(&myGLCD, 310, 275, MyriadProCond2bpp20, COLOR_FG, COLOR_BG, ALIGN_RIGHT, ALIGN_TOP); Label lblTempInMin(&myGLCD, 310, 325, MyriadProCond2bpp20, COLOR_FG, COLOR_BG, ALIGN_RIGHT, ALIGN_BOTTOM); Label lblTempOutMax(&myGLCD, 310, 345, MyriadProCond2bpp20, COLOR_FG, COLOR_BG, ALIGN_RIGHT, ALIGN_TOP); Label lblTempOutMin(&myGLCD, 310, 395, MyriadProCond2bpp20, COLOR_FG, COLOR_BG, ALIGN_RIGHT, ALIGN_BOTTOM); Label lblPressureMax(&myGLCD, 310, 415, MyriadProCond2bpp20, COLOR_FG, COLOR_BG, ALIGN_RIGHT, ALIGN_TOP); Label lblPressureMin(&myGLCD, 310, 465, MyriadProCond2bpp20, COLOR_FG, COLOR_BG, ALIGN_RIGHT, ALIGN_BOTTOM); Label lblBattVoltageOut(&myGLCD, 290, 185, MyriadProCond2bpp20, COLOR_FG, COLOR_BG, ALIGN_CENTER, ALIGN_TOP); BarChart crtTempIn(&myGLCD, 10, 275, 24, 9, 1, 50, COLOR_FG, COLOR_BG, ALIGN_LEFT, ALIGN_TOP); BarChart crtTempOut(&myGLCD, 10, 345, 24, 9, 1, 50, COLOR_FG, COLOR_BG, ALIGN_LEFT, ALIGN_TOP); BarChart crtPressure(&myGLCD, 10, 415, 24, 9, 1, 50, COLOR_FG, COLOR_BG, ALIGN_LEFT, ALIGN_TOP); void setup() { Serial.begin(115200); while (!Serial) {} myGLCD.InitLCD(PORTRAIT); bmp.begin(); rtc.begin(); radio.begin(); radio.setPALevel(RF24_PA_HIGH); network.begin(rf24_channel, rf24_master_node_address); draw_ui(); } void loop() { static int old_h = -1, old_m = -1, old_dow = -1; static float temp_in = 0, temp_out = 0; static int pressure = -1; static bool temp_out_read = false; network.update(); while (network.available()) { RF24NetworkHeader header; network.peek(header); switch (header.type) { case 'T': network.read(header, &temp_out, sizeof(float)); lblTempOutValue.printf("%02.1f �C", temp_out); if (!temp_out_read) { crtTempOut.updateLast(round(temp_out*10)); lblTempOutMax.printf("%02.1f �C", (float)crtTempOut.getMax()/10); lblTempOutMin.printf("%02.1f �C", (float)crtTempOut.getMin()/10); temp_out_read = true; } Serial.print("Got temperature from remote: "); Serial.println(temp_out); break; case 'V': long v; network.read(header, &v, sizeof(long)); lblBattVoltageOut.printf("%1.2fV", (float)v/1000); Serial.print("Got voltage from remote: "); Serial.println(v); break; } } temp_in = bmp.readTemperature(); pressure = round(bmp.readPressure() * 0.0075006168270417); lblTempInValue.printf("%02.1f �C", temp_in); update_pressure(pressure); Time t = rtc.getTime(); if (t.min != old_m) { lblClock.printf("%02d:%02d", t.hour, t.min); if (t.hour != old_h) { crtTempIn.push(round(temp_in*10)); lblTempInMax.printf("%02.1f �C", (float)crtTempIn.getMax()/10); lblTempInMin.printf("%02.1f �C", (float)crtTempIn.getMin()/10); crtTempOut.push(round(temp_out*10)); lblTempOutMax.printf("%02.1f �C", (float)crtTempOut.getMax()/10); lblTempOutMin.printf("%02.1f �C", (float)crtTempOut.getMin()/10); crtPressure.push(pressure); lblPressureMax.printf("%d ��", crtPressure.getMax()); lblPressureMin.printf("%d ��", crtPressure.getMin()); } if (t.dow != old_dow) { lblDate.printf("%s, %d %s %d ����", weekdays[t.dow-1], t.date, months[t.mon-1], t.year); } old_h = t.hour; old_m = t.min; old_dow = t.dow; } delay(1000); } void draw_ui() { myGLCD.fillScr(COLOR_BG); myGLCD.setBackColor(COLOR_BG); myGLCD.setColor(COLOR_FG); lblTempInText.print("������"); lblTempOutText.print("�������"); crtTempIn.drawOuterBorder(2); crtTempOut.drawOuterBorder(2); crtPressure.drawOuterBorder(2); } void update_pressure(int p) { lblPressureValue.printf("%d ��", p); if (p >= 745) { // clear lblPressureIcon.print("0"); } else if (p <= 733){ // rain/snow lblPressureIcon.print("2"); } else { // cloudy lblPressureIcon.print("1"); } }