Advertisement
safwan092

8x8 led matrix arduino driver dht11

Feb 28th, 2018
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.70 KB | None | 0 0
  1. // WWW.ARDUINOARTS.COM
  2. //Based on Macelo Moraes project on instructables: http://www.instructables.com/id/16x8-LED-dot-matrix-with-MAX7219-module/
  3. //Modified by @mrlndr for @arduinoarts.com
  4. //D1
  5. //D2
  6. //D3
  7. //D4
  8. //D5
  9. //D6
  10. //D7= temp
  11. //D8
  12. //D9
  13. //D10=CS
  14. //D11=CLK
  15. //D12=DIN
  16. //D13
  17. //A1
  18. //A2
  19. //A3
  20. //A4
  21. //A5
  22. //
  23.  
  24. #include <MaxMatrix.h> //include matrix library
  25. #include <avr/pgmspace.h>
  26. #include <stdlib.h>
  27. #include "DHT.h" //include the temp sensor library
  28. #define DHTPIN 7 // what pin we're connected to
  29. #define DHTTYPE DHT11 // DHT 11 temp&humid sensor
  30. DHT dht(DHTPIN, DHTTYPE);
  31.  
  32. PROGMEM prog_uchar CH[] = {
  33. 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
  34. 1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
  35. 3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
  36. 5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
  37. 4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
  38. 5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
  39. 5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
  40. 1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
  41. 3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
  42. 3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
  43. 5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
  44. 5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
  45. 2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
  46. 4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
  47. 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
  48. 4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
  49. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
  50. 3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
  51. 4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
  52. 4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
  53. 4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
  54. 4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
  55. 4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
  56. 4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
  57. 4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
  58. 4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
  59. 2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
  60. 2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
  61. 3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
  62. 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
  63. 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
  64. 4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
  65. 5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
  66. 4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
  67. 4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
  68. 4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
  69. 4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
  70. 4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
  71. 4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
  72. 4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
  73. 4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
  74. 3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
  75. 4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
  76. 4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
  77. 4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
  78. 5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
  79. 5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
  80. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
  81. 4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
  82. 4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
  83. 4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
  84. 4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
  85. 5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
  86. 4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
  87. 5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
  88. 5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
  89. 5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
  90. 5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
  91. 4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
  92. 2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
  93. 4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
  94. 2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
  95. 3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
  96. 4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
  97. 2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
  98. 4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
  99. 4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
  100. 4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
  101. 4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
  102. 4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
  103. 3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
  104. 4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
  105. 4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
  106. 3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
  107. 4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
  108. 4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
  109. 3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
  110. 5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
  111. 4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
  112. 4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
  113. 4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
  114. 4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
  115. 4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
  116. 4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
  117. 3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
  118. 4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
  119. 5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
  120. 5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
  121. 5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
  122. 4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
  123. 3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
  124. 3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
  125. 1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
  126. 3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
  127. 4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
  128. };
  129.  
  130. int data = 12; // DIN pin of MAX7219 module
  131. int load = 10; // CS pin of MAX7219 module
  132. int clock = 11; // CLK pin of MAX7219 module
  133. int maxInUse = 4; //change this variable to set how many MAX7219's you'll use
  134. MaxMatrix m(data, load, clock, maxInUse); // define module
  135. byte buffer[10];
  136.  
  137. void setup(){
  138. pinMode(2,INPUT); //button input
  139. m.init(); // module initialize
  140. m.setIntensity(15); // dot matix intensity 0-15
  141. Serial.begin(9600); // serial communication initialize
  142. Serial.println("DHTxx test!");
  143. dht.begin();
  144. }
  145.  
  146. void loop(){
  147.  
  148. printStringWithShift(" ArduinoArts.com ", 100);
  149. int t = dht.readTemperature();
  150. char temp[4];
  151. itoa(t,temp,10); //convert int to char!!!!
  152. Serial.println(temp);
  153. printStringWithShift("temp: ", 100);
  154. printStringWithShift(temp, 100);
  155. printStringWithShift("C ", 100);
  156. if (t<18){printStringWithShift(" Brrrrr Que Frio!!!! ", 100);} //if it´ cold...
  157. if (t>27){printStringWithShift(" Que calor!!!! ", 100);} //if it´ too hot...
  158. if (t>17 && t<28){printStringWithShift(" ;) ", 100);} //if it´ ok!!!
  159. delay(100);
  160. m.shiftLeft(false, true);
  161. }
  162.  
  163.  
  164. void printCharWithShift(char c, int shift_speed){
  165. if (c < 32) return;
  166. c -= 32;
  167. memcpy_P(buffer, CH + 7*c, 7);
  168. m.writeSprite(32, 0, buffer);
  169. m.setColumn(32 + buffer[0], 0);
  170.  
  171. for (int i=0; i<buffer[0]+1; i++)
  172. {
  173. delay(shift_speed);
  174. m.shiftLeft(false, false);
  175. }
  176. }
  177.  
  178. void printStringWithShift(char* s, int shift_speed){
  179. while (*s != 0){
  180. printCharWithShift(*s, shift_speed);
  181. s++;
  182. }
  183. }
  184.  
  185. void printString(char* s)
  186. {
  187. int col = 0;
  188. while (*s != 0)
  189. {
  190. if (*s < 32) continue;
  191. char c = *s - 32;
  192. memcpy_P(buffer, CH + 7*c, 7);
  193. m.writeSprite(col, 0, buffer);
  194. m.setColumn(col + buffer[0], 0);
  195. col += buffer[0] + 1;
  196. s++;
  197. }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement