RuiViana

DHT22_2_7Seg

Aug 17th, 2016
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "DHT.h"
  2.  
  3. #define DHTPIN A0
  4. #define DHTTYPE DHT11
  5.  
  6. DHT dht(DHTPIN, DHTTYPE);
  7.  
  8. int C1 = 3;
  9. int C2 = 2;
  10. int a = 10;
  11. int b = 9;
  12. int c = 8;
  13. int d = 7;
  14. int e = 6;
  15. int f = 5;
  16. int g = 4;
  17. int firstDig, secDig;
  18. float t = 0;
  19. //----------------------------------
  20. void setup()
  21. {
  22. pinMode(C1, OUTPUT);
  23. pinMode(C2, OUTPUT);
  24. digitalWrite(C1, HIGH);
  25. digitalWrite(C2, HIGH);
  26. for (int i = 4; i < 11; i++)
  27. {
  28. pinMode(i, OUTPUT);
  29. }
  30. }
  31. //----------------------------------
  32. void loop()
  33. {
  34. t = dht.readTemperature();
  35. digitalWrite(C1, HIGH);
  36. digitalWrite(C2, HIGH);
  37. firstDig = (int)t / 10;
  38. pintar(firstDig);
  39. digitalWrite(C1, LOW); //liga c1
  40. delay(10);
  41. // if (not(secDig == (int)t % 10)) // para não ficar repintando o display se a temperatura não mudou
  42. // {
  43. digitalWrite(C1, HIGH);
  44. digitalWrite(C2, HIGH);
  45. secDig = (int)t % 10;
  46. pintar(secDig);
  47. digitalWrite(C2, LOW); //liga c2
  48. // }
  49. delay(10);
  50. }
  51. //----------------------------------
  52. void pintar(int numero)
  53. {
  54. switch (numero)
  55. {
  56. case 0:
  57. {
  58. digitalWrite(a, LOW);
  59. digitalWrite(b, LOW);
  60. digitalWrite(c, LOW);
  61. digitalWrite(d, LOW);
  62. digitalWrite(e, LOW);
  63. digitalWrite(f, LOW);
  64. digitalWrite(g, HIGH);
  65. break;
  66. }
  67. case 1:
  68. {
  69. digitalWrite(a, HIGH);
  70. digitalWrite(b, LOW);
  71. digitalWrite(c, LOW);
  72. digitalWrite(d, HIGH);
  73. digitalWrite(e, HIGH);
  74. digitalWrite(f, HIGH);
  75. digitalWrite(g, HIGH);
  76. break;
  77. }
  78. case 2:
  79. {
  80. digitalWrite(a, LOW);
  81. digitalWrite(b, LOW);
  82. digitalWrite(c, HIGH);
  83. digitalWrite(d, LOW);
  84. digitalWrite(e, LOW);
  85. digitalWrite(f, HIGH);
  86. digitalWrite(g, LOW);
  87. break;
  88. }
  89. case 3:
  90. {
  91. digitalWrite(a, LOW);
  92. digitalWrite(b, LOW);
  93. digitalWrite(c, LOW);
  94. digitalWrite(d, LOW);
  95. digitalWrite(e, HIGH);
  96. digitalWrite(f, HIGH);
  97. digitalWrite(g, LOW);
  98. break;
  99. }
  100. case 4:
  101. {
  102. digitalWrite(a, HIGH);
  103. digitalWrite(b, LOW);
  104. digitalWrite(c, LOW);
  105. digitalWrite(d, HIGH);
  106. digitalWrite(e, HIGH);
  107. digitalWrite(f, LOW);
  108. digitalWrite(g, LOW);
  109. break;
  110. }
  111. case 5:
  112. {
  113. digitalWrite(a, LOW);
  114. digitalWrite(b, HIGH);
  115. digitalWrite(c, LOW);
  116. digitalWrite(d, LOW);
  117. digitalWrite(e, HIGH);
  118. digitalWrite(f, LOW);
  119. digitalWrite(g, LOW);
  120. break;
  121. }
  122. case 6:
  123. {
  124. digitalWrite(a, LOW);
  125. digitalWrite(b, HIGH);
  126. digitalWrite(c, LOW);
  127. digitalWrite(d, LOW);
  128. digitalWrite(e, LOW);
  129. digitalWrite(f, LOW);
  130. digitalWrite(g, LOW);
  131. break;
  132. }
  133. case 7:
  134. {
  135. digitalWrite(a, LOW);
  136. digitalWrite(b, LOW);
  137. digitalWrite(c, LOW);
  138. digitalWrite(d, HIGH);
  139. digitalWrite(e, HIGH);
  140. digitalWrite(f, HIGH);
  141. digitalWrite(g, HIGH);
  142. break;
  143. }
  144. case 8:
  145. {
  146. digitalWrite(a, LOW);
  147. digitalWrite(b, LOW);
  148. digitalWrite(c, LOW);
  149. digitalWrite(d, LOW);
  150. digitalWrite(e, LOW);
  151. digitalWrite(f, LOW);
  152. digitalWrite(g, LOW);
  153. break;
  154. }
  155. case 9:
  156. {
  157. digitalWrite(a, LOW);
  158. digitalWrite(b, LOW);
  159. digitalWrite(c, LOW);
  160. digitalWrite(d, LOW);
  161. digitalWrite(e, HIGH);
  162. digitalWrite(f, LOW);
  163. digitalWrite(g, LOW);
  164. break;
  165. }
  166. default:
  167. {
  168. digitalWrite(a, LOW);
  169. digitalWrite(b, HIGH);
  170. digitalWrite(c, HIGH);
  171. digitalWrite(d, LOW);
  172. digitalWrite(e, LOW);
  173. digitalWrite(f, LOW);
  174. digitalWrite(g, LOW);
  175. break;
  176. }
  177. }
  178. }
RAW Paste Data