Display.ino 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // LCD
  2. byte customCharSun[8] = {0b00100, 0b10001, 0b01110, 0b11111, 0b11111, 0b01110, 0b10001, 0b00100};
  3. byte customCharMoon[8] = {0b11000, 0b01110, 0b00110, 0b00111, 0b00111, 0b00110, 0b01110, 0b11000};
  4. byte customCharArrowRight[8] = {0b00000, 0b00100, 0b00110, 0b11111, 0b11111, 0b00110, 0b00100, 0b00000};
  5. //bool displayActive = false;
  6. unsigned long displayLastOnMillis = 0;
  7. void enableDisplay() {
  8. lcd.backlight();
  9. displayActive = true;
  10. displayLastOnMillis = millis();
  11. }
  12. void disableDisplay() {
  13. lcd.noBacklight();
  14. displayActive = false;
  15. }
  16. void extendDisplayTimeout() {
  17. displayLastOnMillis = millis();
  18. }
  19. void handleDisplayTimeout() {
  20. if (displayActive && (millis() - displayLastOnMillis) > (displayTimeout * 1000)) {
  21. disableDisplay();
  22. }
  23. }
  24. void initDisplay() {
  25. lcd.init();
  26. lcd.createChar(0, customCharMoon);
  27. lcd.createChar(1, customCharSun);
  28. lcd.createChar(2, customCharArrowRight);
  29. lcd.setCursor(0, 0);
  30. lcd.print("WiFi-Thermostat ");
  31. lcd.setCursor(0, 1);
  32. lcd.print(" by Flo Kra");
  33. // for ( int i = 0; i < 3; i++) {
  34. // lcd.backlight();
  35. // delay(200);
  36. // lcd.noBacklight();
  37. // delay(200);
  38. // }
  39. lcd.backlight();
  40. delay(1000);
  41. ///lcd.clear();
  42. displayActive = true;
  43. displayLastOnMillis = millis();
  44. }
  45. void updateDisplay() {
  46. long now = millis();
  47. if ( ((now - outTempHumLastUpdate) < 300000) && outTempHumLastUpdate != 0 && whichTempToDisplay == 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
  48. // outside temp has been updated < 5 min ago, last displayed temp was "I" and display interval is overdue
  49. whichTempToDisplay = 2; // 1= I, 2= A
  50. lastDisplayToggle = now;
  51. }
  52. else if ( whichTempToDisplay != 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
  53. whichTempToDisplay = 1; // 1= I, 2= A
  54. lastDisplayToggle = now;
  55. }
  56. lastDisplayUpdate = now;
  57. boolean showTemp = false;
  58. char temp_chararr[6];
  59. char hum_chararr[4];
  60. char tempLabel[2];
  61. if (whichTempToDisplay == 2) {
  62. if ( outTempHumLastUpdate != 0 && (now - outTempHumLastUpdate) < 120000 ) {
  63. showTemp = true;
  64. dtostrf(outTemp, 5, 1, temp_chararr );
  65. sprintf(hum_chararr, "%2i", outHum);
  66. strcpy(tempLabel, "A");
  67. }
  68. }
  69. else {
  70. if ( lastTempUpdate != 0 && (now - lastTempUpdate) < 120000 ) {
  71. showTemp = true;
  72. dtostrf(currTemp, 5, 1, temp_chararr );
  73. sprintf(hum_chararr, "%2i", currHum);
  74. strcpy(tempLabel, "I");
  75. }
  76. }
  77. // LCD line 1
  78. // print temperature incl = and ° symbol + humidity to lcd, line 1, first 11 chars
  79. lcd.setCursor(0, 0);
  80. if (showTemp) {
  81. //lcd.write(0x3D); // = Zeichen
  82. lcd.print(tempLabel);
  83. lcd.print(" ");
  84. lcd.print(temp_chararr);
  85. lcd.write(0xDF); // degree symbol
  86. lcd.print(" ");
  87. if (currHum == 0) lcd.print("--");
  88. else if (currHum < 10) {
  89. lcd.print(" ");
  90. lcd.print(hum_chararr);
  91. }
  92. else {
  93. lcd.print(hum_chararr);
  94. }
  95. lcd.print("%");
  96. lcd.print(" ");
  97. }
  98. else {
  99. lcd.print(" ");
  100. }
  101. // display current mode on LCD
  102. lcd.setCursor(13, 0);
  103. if (heatingMode > 0) {
  104. if ( heatingMode == 1 ) { // day/normal mode
  105. lcd.print(" ");
  106. lcd.write((uint8_t)1); // sun symbol if mode is day/normal
  107. lcd.print(" ");
  108. }
  109. else if ( heatingMode == 2 ) { // night/reduction mode
  110. lcd.print(" ");
  111. lcd.write((uint8_t)0); // moon symbol if mode is night/reduction
  112. lcd.print(" ");
  113. }
  114. }
  115. else lcd.print(" "); // mode is heating off
  116. float curr_setTemp;
  117. if (heatingMode == 1) curr_setTemp = setTemp;
  118. else if (heatingMode == 2) curr_setTemp = setTempLow;
  119. char currSetTemp_chararr[6];
  120. dtostrf(curr_setTemp, 5, 1, currSetTemp_chararr );
  121. // LCD line 2
  122. // display target temperature to line 2, 8 chars length incl space at the end
  123. lcd.setCursor(0, 1);
  124. // when the heating mode is OFF, do not display target temp - instead show "Heating off" info in line 2
  125. if ( heatingMode == 0 ) {
  126. // 1234567890123456
  127. lcd.print(" Heizung aus ");
  128. }
  129. else {
  130. lcd.write((uint8_t)2); // Pfeil rechts
  131. lcd.print(" ");
  132. lcd.print(currSetTemp_chararr);
  133. lcd.write(0xDF); // degree symbol
  134. lcd.print(" ");
  135. // display status info to line 2 from char 9 -> 8 chars length
  136. lcd.setCursor(8, 1);
  137. lcd.print(" ");
  138. if (turnHeatingOn) {
  139. // 1234567
  140. lcd.print("heizen ");
  141. }
  142. else if ( heatingMode == 1 ) { // day/normal mode
  143. // 1234567
  144. lcd.print(" ");
  145. }
  146. else if ( heatingMode == 2 ) { // night/reduction mode
  147. // 1234567
  148. lcd.print("Absenk.");
  149. }
  150. else lcd.print(" ");
  151. }
  152. }