Advertisement
RuiViana

Array de LED com DHT11

Jun 30th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.86 KB | None | 0 0
  1. /*
  2. Nome do Projeto: Matrix_8x24_DHT11
  3. Nome do Aquivo: Matrix_8x24_DHT11.ino
  4. Dependências: DHT.h Biblioteca de DHT11
  5. MCU: ATmega
  6. Board: Arduino Uno/Mega/Mini
  7. Compilador N/A
  8. IDE: Arduino IDE 1.0.6
  9. Hardware: Arduino UNO/MEGA/Mini
  10. Escrito por: Rui Viana
  11. Data: 30/06/2015
  12. Uso: Didático
  13. Desenhos Matrix_8x24_DHT11.png
  14. Copyright @ N/A
  15.  
  16. Este programa é software livre;
  17. e é distribuído na esperança que possa ser útil, mas SEM QUALQUER GARANTIA;
  18. mesmo sem a garantia implícita de COMERCIALIZAÇÃO ou ADEQUAÇÃO A UM DETERMINADO FIM.
  19.  
  20. REVISIONS: (latest entry first)
  21. 2015-06-30 - Matrix_8x24_DHT11.ino - First release
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. Descrição:
  24.  
  25. Este código utiliza a biblioteca DHT.h para ler sensores de umidade e de temperatura.
  26. Le os valores do DHT11 e mostra em uma matriz de LED de 8x24.
  27. os caracteres são no formato 7 x 5.
  28. As funções de display copiei do link:
  29. http://www.instructables.com/id/48x8-SCROLLING-MATRIX-LED-DISPLAY-USING-ARDUINO-CO/?ALLSTEPS
  30.  
  31. Acrescentei os caracteres minúsculos e símbolos, e os comandos que medem a temperatura e
  32. umidade, transformando-as em string e depois em array.
  33. Em seguinda enviando-as para o display.
  34.  
  35. Quero aqui agradecer o esforço do Celso Eiju Ito,
  36. pois o funcionamento das funções de mostrar a temperatura em float só foi possível com a ajuda dele.
  37.  
  38. */
  39.  
  40. //************ Variaveis e constantes ************
  41. #include "DHT.h" // Inclui a biblioteca do DHT11
  42. #define DHTPIN A1 // pino que estamos conectado
  43. #define DHTTYPE DHT11 // DHT 11
  44. DHT dht(DHTPIN, DHTTYPE);
  45.  
  46. int x;
  47. int y;
  48. int latchPin1 = 5; //Arduino pin connected to blue 12 RCLK of 74HC595
  49. int clockPin1 = 6; //Arduino pin connected to green 11 SRCLK of 74HC595
  50. int dataPin1 = 7; //Arduino pin connected to violet 14 SER of 74HC595
  51.  
  52. //-- Rows (Positive Anodes) --
  53. int latchPin2 = 9; //Arduino pin connected to yellow Latch 12 RCLK of 74HC595
  54. int clockPin2 = 10; //Arduino pin connected to white Clock 11 SRCLK of 74HC595
  55. int dataPin2 = 8; //Arduino pin connected to grey Data 14 SER of 74HC595
  56.  
  57. //=== B I T M A P ===
  58. //Bits in this array represents one LED of the matrix
  59. // 8 is # of rows, 7 is # of LED matrix we have
  60. byte bitmap[8][7]; // Change the 7 to however many matrices you want to use.
  61. int numZones = sizeof(bitmap) / 8;
  62. int maxZoneIndex = numZones-1;
  63. int numCols = numZones * 8;
  64.  
  65. const byte alphabets[][5] = {
  66. {0,0,0,0,0}, // Espaço
  67. {0x00, 0x00, 0xFA, 0x00, 0x00}, // !
  68. {0x00, 0xE0, 0x00, 0xE0, 0x00}, // "
  69. {0x28, 0xFE, 0x28, 0xFE, 0x28}, // #
  70. {0x24, 0x54, 0xFE, 0x54, 0x48}, // $
  71. {0xC4, 0xC8, 0x10, 0x26, 0x46}, // %
  72. {0x6C, 0x92, 0xAA, 0x44, 0x0A}, // &
  73. {0x00, 0xA0, 0xC0, 0x00, 0x00}, // '
  74. {0x00, 0x38, 0x44, 0x82, 0x00}, // (
  75. {0x00, 0x82, 0x44, 0x38, 0x00}, // )
  76. {0x10, 0x54, 0x38, 0x54, 0x10}, // *
  77. {0x10, 0x10, 0x7C, 0x10, 0x10}, // +
  78. {0x00, 0x0A, 0x0C, 0x00, 0x00}, // ,
  79. {0x10, 0x10, 0x10, 0x10, 0x10}, // -
  80. {0x00, 0x06, 0x06, 0x00, 0x00}, // .
  81. {0x04, 0x08, 0x10, 0x20, 0x40}, // /
  82. {0x7C, 0x8A, 0x92, 0xA2, 0x7C}, // 0
  83. {0x00, 0x42, 0xFE, 0x02, 0x00}, // 1
  84. {0x42, 0x86, 0x8A, 0x92, 0x62}, // 2
  85. {0x84, 0x82, 0xA2, 0xD2, 0x8C}, // 3
  86. {0x18, 0x28, 0x48, 0xFE, 0x08}, // 4
  87. {0xE4, 0xA2, 0xA2, 0xA2, 0x9C}, // 5
  88. {0x3C, 0x52, 0x92, 0x92, 0xC}, // 6
  89. {0x80, 0x8E, 0x90, 0xA0, 0xC0}, // 7
  90. {0x6C, 0x92, 0x92, 0x92, 0x6C}, // 8
  91. {0x60, 0x92, 0x92, 0x94, 0x78}, // 9
  92.  
  93. {0x00, 0x6C, 0x6C, 0x00, 0x00}, // :
  94. {0x00, 0x6A, 0x6C, 0x00, 0x00}, // ;
  95. {0x00, 0x10, 0x28, 0x44, 0x82}, // <
  96. {0x28, 0x28, 0x28, 0x28, 0x28}, // =
  97. {0x82, 0x44, 0x28, 0x10, 0x00}, // >
  98. {0x40, 0x80, 0x8A, 0x90, 0x60}, // ?
  99. {0x4C, 0x92, 0x9E, 0x82, 0x7C}, // @
  100. {0x7E, 0x88, 0x88, 0x88, 0x7E}, // A
  101. {0xFE, 0x92, 0x92, 0x92, 0x6C}, // B
  102. {0x7C, 0x82, 0x82, 0x82, 0x44}, // C
  103. {0xFE, 0x82, 0x82, 0x44, 0x38}, // D
  104. {0xFE, 0x92, 0x92, 0x92, 0x82}, // E
  105. {0xFE, 0x90, 0x90, 0x80, 0x80}, // F
  106. {0x7C, 0x82, 0x82, 0x8A, 0x4C}, // G
  107. {0xFE, 0x10, 0x10, 0x10, 0xFE}, // H
  108. {0x00, 0x82, 0xFE, 0x82, 0x00}, // I
  109. {0x04, 0x02, 0x82, 0xFC, 0x80}, // J
  110. {0xFE, 0x10, 0x28, 0x44, 0x82}, // K
  111. {0xFE, 0x02, 0x02, 0x02, 0x02}, // L
  112. {0xFE, 0x40, 0x20, 0x40, 0xFE}, // M
  113. {0xFE, 0x20, 0x10, 0x08, 0xFE}, // N
  114. {0x7C, 0x82, 0x82, 0x82, 0x7C}, // O
  115. {0xFE, 0x90, 0x90, 0x90, 0x60}, // P
  116. {0x7C, 0x82, 0x8A, 0x84, 0x7A}, // Q
  117. {0xFE, 0x90, 0x98, 0x94, 0x62}, // R
  118. {0x62, 0x92, 0x92, 0x92, 0x8C}, // S
  119. {0x80, 0x80, 0xFE, 0x80, 0x80}, // T
  120. {0xFC, 0x02, 0x02, 0x02, 0xFC}, // U
  121. {0xF8, 0x04, 0x02, 0x04, 0xF8}, // V
  122. {0xFE, 0x04, 0x18, 0x04, 0xFE}, // W
  123. {0xC6, 0x28, 0x10, 0x28, 0xC6}, // X
  124. {0xC0, 0x20, 0x1E, 0x20, 0xC0}, // Y
  125. {0x86, 0x8A, 0x92, 0xA2, 0xC2}, // Z
  126.  
  127. {0x00, 0x00, 0xFE, 0x82, 0x82}, // [
  128. {0x40, 0x20, 0x10, 0x08, 0x04}, // \
  129. {0x82, 0x82, 0xFE, 0x00, 0x00}, // ]
  130. {0x20, 0x40, 0x80, 0x40, 0x20}, // ^
  131. {0x02, 0x02, 0x02, 0x02, 0x02}, // _
  132. {0x00, 0x80, 0x40, 0x20, 0x00}, // `
  133. {0x00, 0x00, 0x00, 0x00, 0x00}, // null
  134.  
  135. {0x04, 0x2A, 0x2A, 0x2A, 0x1E}, // a
  136. {0xFE, 0x12, 0x22, 0x22, 0x1C}, // b
  137. {0x1C, 0x22, 0x22, 0x22, 0x04}, // c
  138. {0x1C, 0x22, 0x22, 0x12, 0xFE}, // d
  139. {0x1C, 0x2A, 0x2A, 0x2A, 0x18}, // e
  140. {0x10, 0x7E, 0x90, 0x80, 0x40}, // f
  141. {0x10, 0x28, 0x2A, 0x2A, 0x3C}, // g
  142. {0xFE, 0x10, 0x20, 0x20, 0x1E}, // h
  143. {0x00, 0x22, 0xBE, 0x02, 0x00}, // i
  144. {0x04, 0x02, 0x22, 0xBC, 0x00}, // j
  145. {0x00, 0xFE, 0x08, 0x14, 0x22}, // k
  146. {0x00, 0x82, 0xFE, 0x02, 0x00}, // l
  147. {0x3E, 0x20, 0x18, 0x20, 0x1E}, // m
  148. {0x3E, 0x10, 0x20, 0x20, 0x1E}, // n
  149. {0x1C, 0x22, 0x22, 0x22, 0x1C}, // o
  150. {0x3E, 0x28, 0x28, 0x28, 0x10}, // p
  151. {0x10, 0x28, 0x28, 0x18, 0x3E}, // q
  152. {0x3E, 0x10, 0x20, 0x20, 0x10}, // r
  153. {0x12, 0x2A, 0x2A, 0x2A, 0x04}, // s
  154. {0x20, 0xFC, 0x22, 0x02, 0x04}, // t
  155. {0x3C, 0x02, 0x02, 0x04, 0x3E}, // u
  156. {0x38, 0x04, 0x02, 0x04, 0x38}, // v
  157. {0x3C, 0x02, 0x0C, 0x02, 0x3C}, // w
  158. {0x22, 0x14, 0x08, 0x14, 0x22}, // x
  159. {0x30, 0x0A, 0x0A, 0x0A, 0x3C}, // y
  160. {0x22, 0x26, 0x2A, 0x32, 0x22}, // z
  161.  
  162. {0x00, 0x10, 0x6C, 0x82, 0x00}, // {
  163. {0x00, 0x00, 0xFE, 0x00, 0x00}, // |
  164. {0x00, 0x82, 0x6C, 0x10, 0x00}, // }
  165. {0x10, 0x10, 0x54, 0x38, 0x10}, //->
  166. {0x10, 0x38, 0x54, 0x10, 0x10}, //<-
  167. };
  168.  
  169. char msg[22] ;
  170. // char msg[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  171. //************************ setup() ***********************
  172. void setup()
  173. {
  174. dht.begin(); // inicializa o Sensor
  175. pinMode(latchPin1, OUTPUT);
  176. pinMode(clockPin1, OUTPUT);
  177. pinMode(dataPin1, OUTPUT);
  178.  
  179. pinMode(latchPin2, OUTPUT);
  180. pinMode(clockPin2, OUTPUT);
  181. pinMode(dataPin2, OUTPUT);
  182.  
  183. //-- Clear bitmap --
  184. for (int row = 0; row > 8; row++)
  185. {
  186. for (int zone = 0; zone <= maxZoneIndex; zone++)
  187. {
  188. bitmap[row][zone] = 0;
  189. }
  190. }
  191. }
  192. //************************ RefreshDisplay() ***********************
  193. // This routine takes whatever we've setup in the bitmap array and display it on the matrix
  194. void RefreshDisplay()
  195. {
  196. for (int row = 0; row < 8; row++)
  197. {
  198. int rowbit = 1 << row;
  199. digitalWrite(latchPin2, LOW); //Hold latchPin LOW for as long as we're transmitting data
  200. shiftOut(dataPin2, clockPin2, MSBFIRST, rowbit); //Transmit data
  201. //-- Start sending column bytes --
  202. digitalWrite(latchPin1, LOW); //Hold latchPin LOW for as long as we're transmitting data
  203. //-- Shift out to each matrix (zone is 8 columns represented by one matrix)
  204. for (int zone = maxZoneIndex; zone >= 0; zone--)
  205. {
  206. shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
  207. }
  208. //-- Done sending Column bytes, flip both latches at once to eliminate flicker
  209. digitalWrite(latchPin1, HIGH);
  210. digitalWrite(latchPin2, HIGH);
  211. //-- Wait a little bit to let humans see what we've pushed out onto the matrix --
  212. delayMicroseconds(500);
  213. }
  214. }
  215. //************************ Plot() ***********************
  216. // Converts row and colum to actual bitmap bit and turn it off/on
  217. void Plot(int col, int row, bool isOn)
  218. {
  219. int zone = col / 8;
  220. int colBitIndex = x % 8;
  221. byte colBit = 1 << colBitIndex;
  222. if (isOn)
  223. bitmap[row][zone] = bitmap[y][zone] | colBit;
  224. else
  225. bitmap[row][zone] = bitmap[y][zone] & (~colBit);
  226. }
  227. //************************ AlphabetSoup() ***********************
  228. // Plot each character of the message one column at a time, updated the display, shift bitmap left.
  229. void AlphabetSoup()
  230. {
  231. // char msg[] = "YOUR TEXT "; // Era aqui, mudei para o ínicio
  232. for (int charIndex=0; charIndex < (sizeof(msg)-1); charIndex++)
  233. {
  234. int alphabetIndex = msg[charIndex] - 0x20; // Era "@", mudei para 0x20 para aumentar o inicio da tabela
  235. if (alphabetIndex < 0) alphabetIndex=0;
  236. //-- Draw one character of the message --
  237. for (int col = 0; col < 6; col++)
  238. {
  239. for (int row = 0; row < 8; row++)
  240. {
  241. bool isOn = 0;
  242. if (col<5) isOn = bitRead( alphabets[alphabetIndex][col], 7-row ) == 1;
  243. Plot( numCols-1, row, isOn);
  244. }
  245. //-- The more times you repeat this loop, the slower we would scroll --
  246. for (int refreshCount=0; refreshCount < 7; refreshCount++) //change this value to vary speed
  247. RefreshDisplay();
  248. //-- Shift the bitmap one column to left --
  249. for (int row=0; row<8; row++)
  250. {
  251. for (int zone=0; zone < numZones; zone++)
  252. {
  253. bitmap[row][zone] = bitmap[row][zone] >> 1;
  254. // Roll over lowest bit from the next zone as highest bit of this zone.
  255. if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7,
  256. bitRead(bitmap[row][zone+1],0));
  257. }
  258. }
  259. }
  260. }
  261. }
  262. //***************************** loop() **************************
  263. void loop()
  264. {
  265. float Celso; // Varialvel para guardar valor de temperatura
  266. // Varialvel em homengem ao Celso kkkkkk
  267. int humidade; // Varialvel para guardar valor de umidade
  268. String Display; // Varialvel tipo string para guardar o texto para o display
  269. Celso = dht.readTemperature(); // Le temperatura no DHT11
  270. humidade = dht.readHumidity(); // Le humidade no DHT11
  271.  
  272. Display = "C:"; // C: no texto
  273. Display += Celso; // valor da temperatura no texto
  274. Display += " H:"; // H: no texto
  275. Display += humidade; // valor da umidade no texto
  276. Display.toCharArray(msg, 16); // string para array
  277.  
  278. AlphabetSoup(); // chama rotina para display
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement