123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- // LCD
- byte customCharSun[8] = {0b00100, 0b10001, 0b01110, 0b11111, 0b11111, 0b01110, 0b10001, 0b00100};
- byte customCharMoon[8] = {0b11000, 0b01110, 0b00110, 0b00111, 0b00111, 0b00110, 0b01110, 0b11000};
- byte customCharArrowRight[8] = {0b00000, 0b00100, 0b00110, 0b11111, 0b11111, 0b00110, 0b00100, 0b00000};
- byte customCharDegC[8] = {0b01000, 0b10100, 0b01000, 0b00011, 0b00100, 0b00100, 0b00011, 0b00000};
- //bool displayActive = false;
- unsigned long displayLastOnMillis = 0;
- void enableDisplay() {
- lcd.backlight();
- displayActive = true;
- displayLastOnMillis = millis();
- }
- void disableDisplay() {
- lcd.noBacklight();
- displayActive = false;
- }
- void extendDisplayTimeout() {
- displayLastOnMillis = millis();
- }
- void handleDisplayTimeout() {
- if (displayActive && (millis() - displayLastOnMillis) > (displayTimeout * 1000)) {
- disableDisplay();
- }
- }
- void initDisplay() {
- lcd.init();
- lcd.createChar(0, customCharMoon);
- lcd.createChar(1, customCharSun);
- lcd.createChar(2, customCharArrowRight);
- lcd.createChar(3, customCharDegC);
- lcd.setCursor(0, 0);
- lcd.print("WiFiThermostat ");
- lcd.setCursor(0, 1);
- lcd.print(" (c) 2018 FloKra");
- // for ( int i = 0; i < 3; i++) {
- // lcd.backlight();
- // delay(200);
- // lcd.noBacklight();
- // delay(200);
- // }
- lcd.backlight();
- //delay(1000);
- ///lcd.clear();
- displayActive = true;
- displayLastOnMillis = millis();
- }
- void updateDisplay() {
- long now = millis();
- if ( ((now - outTempHumLastUpdate) < 300000) && outTempHumLastUpdate != 0 && whichTempToDisplay == 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
- // outside temp has been updated < 5 min ago, last displayed temp was "I" and display interval is overdue
- whichTempToDisplay = 2; // 1= I, 2= A
- lastDisplayToggle = now;
- }
- else if ( whichTempToDisplay != 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
- whichTempToDisplay = 1; // 1= I, 2= A
- lastDisplayToggle = now;
- }
- lastDisplayUpdate = now;
- boolean showTemp = false;
- char temp_chararr[6];
- char hum_chararr[4];
- char tempLabel[2];
- if (whichTempToDisplay == 2) {
- if ( outTempHumLastUpdate != 0 && (now - outTempHumLastUpdate) < 120000 ) {
- showTemp = true;
- dtostrf(outTemp, 5, 1, temp_chararr );
- sprintf(hum_chararr, "%2i", outHum);
- strcpy(tempLabel, "A");
- }
- }
- else {
- if ( lastTempUpdate != 0 && (now - lastTempUpdate) < 120000 ) {
- showTemp = true;
- dtostrf(currTemp, 5, 1, temp_chararr );
- sprintf(hum_chararr, "%2i", currHum);
- strcpy(tempLabel, "I");
- }
- }
- // 12345667890123456
- // =20.0° 35% >22.5°
- // A -10.2° 95% N
- // A 22.2° 95% N
- // A 5.2° 95% N
-
-
- // LCD line 1
- // print temperature incl = and ° symbol + humidity to lcd, line 1, first 11 chars
- lcd.setCursor(0, 0);
-
-
- if (showTemp) {
- //lcd.write(0x3D); // = Zeichen
- lcd.print(tempLabel);
- lcd.print(" ");
- lcd.print(temp_chararr);
- //lcd.write(0xDF); // degree symbol
- lcd.write((uint8_t)3); // °C symbol
- lcd.print(" ");
- if (currHum == 0) lcd.print("--");
- else if (currHum < 10) {
- lcd.print(" ");
- lcd.print(hum_chararr);
- }
- else {
- lcd.print(hum_chararr);
- }
- lcd.print("%");
- lcd.print(" ");
- }
- else {
- lcd.print(" ");
- }
- // display current mode on LCD
- lcd.setCursor(13, 0);
- if (heatingMode > 0) {
- if ( heatingMode == 1 ) { // day/normal mode
- lcd.print(" ");
- lcd.write((uint8_t)1); // sun symbol if mode is day/normal
- lcd.print(" ");
- }
- else if ( heatingMode == 2 ) { // night/reduction mode
- lcd.print(" ");
- lcd.write((uint8_t)0); // moon symbol if mode is night/reduction
- lcd.print(" ");
- }
- }
- else lcd.print(" "); // mode is heating off
- float curr_setTemp;
- if (heatingMode == 1) curr_setTemp = setTemp;
- else if (heatingMode == 2) curr_setTemp = setTempLow;
- char currSetTemp_chararr[6];
- dtostrf(curr_setTemp, 5, 1, currSetTemp_chararr );
- // LCD line 2
- // display target temperature to line 2, 8 chars length incl space at the end
- lcd.setCursor(0, 1);
- // when the heating mode is OFF, do not display target temp - instead show "Heating off" info in line 2
- if ( heatingMode == 0 ) {
- // 1234567890123456
- lcd.print(" Heizung aus ");
- }
- else {
- lcd.write((uint8_t)2); // Pfeil rechts
- lcd.print(" ");
- lcd.print(currSetTemp_chararr);
- //lcd.write(0xDF); // degree symbol
- lcd.write((uint8_t)3); // °C symbol
- lcd.print(" ");
- // display status info to line 2 from char 9 -> 8 chars length
- lcd.setCursor(8, 1);
- lcd.print(" ");
- if (turnHeatingOn) {
- // 1234567
- lcd.print("heizen ");
- }
- else if ( heatingMode == 1 ) { // day/normal mode
- // 1234567
- lcd.print(" ");
- }
- else if ( heatingMode == 2 ) { // night/reduction mode
- // 1234567
- lcd.print("Absenk.");
- }
- else lcd.print(" ");
- }
- }
|