KRITSADA

Temperature Display Using Matrix Screen

Feb 24th, 2021
1,129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <MaxMatrix.h>
  2. #include "DHT.h"
  3.  
  4. DHT dht;
  5.  
  6. #include <avr/pgmspace.h>
  7.  
  8. //PROGMEM prog_uchar CH[] = {
  9. const unsigned char CH[] PROGMEM = {
  10. 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  11. 1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
  12. 3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
  13. 5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
  14. 4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
  15. 5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
  16. 5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
  17. 1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
  18. 3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
  19. 3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
  20. 5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
  21. 5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
  22. 2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
  23. 4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
  24. 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
  25. 4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
  26. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
  27. 3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
  28. 4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
  29. 4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
  30. 4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
  31. 4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
  32. 4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
  33. 4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
  34. 4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
  35. 4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
  36. 2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
  37. 2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
  38. 3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
  39. 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
  40. 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
  41. 4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
  42. 5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
  43. 4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  44. 4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  45. 4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  46. 4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  47. 4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  48. 4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  49. 4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  50. 4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  51. 3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  52. 4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  53. 4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  54. 4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  55. 5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  56. 5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  57. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  58. 4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  59. 4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  60. 4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  61. 4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  62. 5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  63. 4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  64. 5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  65. 5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  66. 5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  67. 5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  68. 4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
  69. 2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
  70. 4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
  71. 2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
  72. 3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
  73. 4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
  74. 2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
  75. 4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
  76. 4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
  77. 4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
  78. 4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
  79. 4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
  80. 3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
  81. 4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
  82. 4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
  83. 3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
  84. 4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
  85. 4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
  86. 3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
  87. 5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
  88. 4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
  89. 4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
  90. 4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
  91. 4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
  92. 4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
  93. 4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
  94. 3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
  95. 4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
  96. 5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
  97. 5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
  98. 5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
  99. 4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
  100. 3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
  101. 3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
  102. 1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
  103. 3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
  104. 4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
  105. };
  106.  
  107. int data = 12;    // DIN pin of MAX7219 module
  108. int load = 10;    // CS pin of MAX7219 module
  109. int clock = 11;  // CLK pin of MAX7219 module
  110.  
  111. int maxInUse = 1;  //how many MAX7219 are connected
  112.  
  113. MaxMatrix m(data, load, clock, maxInUse); // define Library
  114.  
  115. byte buffer[10];
  116.  
  117. char string1[] = "";  // Scrolling Text
  118.  
  119.  
  120. void setup(){
  121.   m.init(); // module MAX7219
  122.   m.setIntensity(5); // LED Intensity 0-15
  123.   dht.setup(7);
  124.    Serial.begin(9600);
  125. }
  126.  
  127. void loop(){
  128.  
  129.  int t = dht.getTemperature();
  130.   char temp[4];
  131.   itoa(t,temp,10); //convert int to char!!!!
  132.   Serial.println(temp);
  133.   //printStringWithShift("Ramadan Mubarak - temp: ", random(20,80));
  134.   printStringWithShift(temp,100);
  135.   printStringWithShift("  ", 100);
  136.   byte c;
  137.   delay(100);
  138.   m.shiftLeft(false, true);
  139.  
  140. }
  141.  
  142. // Put extracted character on Display
  143. void printCharWithShift(char c, int shift_speed){
  144.   if (c < 32) return;
  145.   c -= 32;
  146.   memcpy_P(buffer, CH + 7*c, 7);
  147.   m.writeSprite(maxInUse*8, 0, buffer);
  148.   m.setColumn(maxInUse*8 + buffer[0], 0);
  149.  
  150.   for (int i=0; i<buffer[0]+1; i++)
  151.   {
  152.     delay(shift_speed);
  153.     m.shiftLeft(false, false);
  154.   }
  155. }
  156.  
  157. // Extract characters from Scrolling text
  158. void printStringWithShift(char* s, int shift_speed){
  159.   while (*s != 0){
  160.     printCharWithShift(*s, shift_speed);
  161.     s++;
  162.   }
  163. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×