Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. //Bibliotecas
  2. #include <Wire.h> //Comunicacao I2C
  3. #include <Adafruit_GFX.h> //Graficos
  4. #include <MCUFRIEND_kbv.h> //Hardware ST7735
  5. #include <OneWire.h>
  6. #include <DallasTemperature.h>
  7.  
  8. //DS18B20
  9. #define ONE_WIRE_BUS 19
  10. OneWire oneWire(ONE_WIRE_BUS);
  11. DallasTemperature sensors(&oneWire);
  12. uint8_t sensor1[8] = { 0x28, 0xF4, 0x67, 0x79, 0x97, 0x10, 0x03, 0x97 };
  13. uint8_t sensor2[8] = { 0x28, 0x92, 0x96, 0x79, 0x97, 0x10, 0x03, 0x8D };
  14.  
  15. //TFT
  16. MCUFRIEND_kbv tft; //Indicar para a biblioteca o TFT
  17. #include <Fonts/FreeSans9pt7b.h>
  18. #include <Fonts/FreeSans12pt7b.h>
  19. #include <Fonts/FreeSerif12pt7b.h>
  20. #include <FreeDefaultFonts.h>
  21. #define BLACK 0x0000
  22. #define RED 0xF800
  23. #define GREEN 0x07E0
  24. #define WHITE 0xFFFF
  25. #define GREY 0x8410
  26.  
  27. //Botoes
  28. #define B1 21 //Botao1
  29. int EB1; //Estado do B1
  30.  
  31. //Variaveis
  32. int M; //Menu
  33. float TS1; //Temperatura do S1
  34. float TS2; //Temperatura do S2
  35. float TIP;
  36. float TIM;
  37. int CP;
  38. int CM;
  39. int RR;
  40.  
  41. void setup(void)
  42. {
  43. Serial.begin(9600); //Comunicacao serial em 9600baud
  44. uint16_t ID = tft.readID(); //16 bits para a leitura do TFT
  45. if (ID == 0xD3) ID = 0x9481; //ID do ST7735
  46. sensors.begin();
  47. tft.begin(ID); //Inicia a comunicacao com o ST7735
  48. tft.setRotation(0); //Rotacao para portrato
  49. pinMode(B1, INPUT);
  50. }
  51.  
  52. void loop(void)
  53. {
  54. bemvindo();
  55. delay(1000);
  56. }
  57.  
  58. void getTempSensor(DeviceAddress deviceAddress)
  59. {
  60. float a = sensors.getTempC(deviceAddress);
  61. if (deviceAddress == sensor1) {
  62. TS1 = a;
  63. } if (deviceAddress == sensor2) {
  64. TS2 = a;
  65. }
  66. }
  67.  
  68. void comparacao()
  69. {
  70. tft.fillScreen(BLACK);
  71. showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
  72. showmsgXY(0, 40, 1, &FreeSans9pt7b, "Comparacao");
  73. pbranco();
  74. tft.setCursor(0, 80);
  75. tft.print("Esfrie a area do exame.");
  76. tft.setCursor(0, 100);
  77. tft.print("Pressione o botao para");
  78. tft.setCursor(0, 120);
  79. tft.print("prosseguir");
  80. EB1 = digitalRead(B1);
  81. if (EB1 == HIGH) {
  82. M = 2;
  83. delay(2000);
  84. calculo();
  85. } else {
  86. delay(5000);
  87. comparacao();
  88. }
  89. }
  90.  
  91. void calculo()
  92. {
  93. tft.fillScreen(BLACK);
  94. showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
  95. showmsgXY(0, 40, 1, &FreeSans9pt7b, "Comparacao");
  96. showmsgXY(0, 70, 1, &FreeSans9pt7b, "Estado");
  97. showmsgXY(0, 110, 1, &FreeSans9pt7b, "Temperatura inicial (pele)");
  98. showmsgXY(0, 150, 1, &FreeSans9pt7b, "Temperatura da pele");
  99. showmsgXY(0, 190, 1, &FreeSans9pt7b, "Temperatura inicial (mancha)");
  100. showmsgXY(0, 230, 1, &FreeSans9pt7b, "Temperatura da mancha");
  101.  
  102. pbranco();
  103. tft.setCursor(20, 90);
  104. tft.print("Aperte o botao para iniciar");
  105. tft.setCursor(20, 130);
  106. float TIP = TS1;
  107. tft.print(TIP);
  108. tft.setCursor(20, 210);
  109. float TIM = TS2;
  110. tft.print(TIM);
  111. EB1 = digitalRead(B1);
  112. if (EB1 == HIGH)
  113. {
  114. diferenca();
  115. }
  116. delay(5000);
  117. calculo();
  118. }
  119.  
  120. void diferenca()
  121. {
  122. tft.fillScreen(BLACK);
  123. showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
  124. showmsgXY(0, 40, 1, &FreeSans9pt7b, "Comparacao");
  125. showmsgXY(0, 70, 1, &FreeSans9pt7b, "Estado");
  126. showmsgXY(0, 110, 1, &FreeSans9pt7b, "Temperatura inicial (pele)");
  127. showmsgXY(0, 150, 1, &FreeSans9pt7b, "Temperatura da pele");
  128. showmsgXY(0, 190, 1, &FreeSans9pt7b, "Temperatura inicial (mancha)");
  129. showmsgXY(0, 230, 1, &FreeSans9pt7b, "Temperatura da mancha");
  130. pbranco();
  131. tft.setCursor(20, 90);
  132. tft.print("Calculando...");
  133. tft.setCursor(20, 130);
  134. float TIP = TS1;
  135. tft.print(TIP);
  136. tft.setCursor(20, 210);
  137. float TIM = TS2;
  138. tft.print(TIM);
  139. delay (500);
  140. EB1 = digitalRead(B1);
  141. do {
  142. sensors.requestTemperatures();
  143. pbranco();
  144. getTempSensor(sensor1);
  145. tft.setCursor(20, 170);
  146. tft.print(TS1);
  147. getTempSensor(sensor2);
  148. tft.setCursor(20, 250);
  149. tft.print(TS2);
  150. delay(500);
  151. if (TS1 <= TIP) {
  152. CP++;
  153. } if (TS2 <= TIM) {
  154. CM++;
  155. } if (TS1 >= TIP && TS2 >= TIM) {
  156. resultado();
  157. }
  158. delay(200);
  159. } while (EB1 == LOW);
  160. }
  161.  
  162. void resultado()
  163. {
  164. tft.fillScreen(RED);
  165. exit(0);
  166. }
  167.  
  168. void bemvindo()
  169. {
  170. tft.fillScreen(BLACK);
  171. showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
  172. showmsgXY(0, 40, 1, &FreeSans9pt7b, "Feira Industrial ETEC HAS");
  173. pbranco();
  174. tft.setCursor(0, 170);
  175. tft.print("Pressione o botao para medir");
  176. tft.setCursor(0, 190);
  177. tft.print("a temperatura inicial");
  178. EB1 = digitalRead(B1);
  179. if (EB1 == HIGH) {
  180. showmsgXY(0, 70, 1, &FreeSans9pt7b, "Temperatura inicial (pele)");
  181. showmsgXY(0, 110, 1, &FreeSans9pt7b, "Temperatura inicial (mancha)");
  182. sensors.requestTemperatures();
  183. pbranco();
  184. getTempSensor(sensor1);
  185. tft.setCursor(20, 90);
  186. float TIP = TS1;
  187. tft.print(TS1);
  188. getTempSensor(sensor2);
  189. tft.setCursor(20, 130);
  190. float TIM = TS2;
  191. tft.print(TS2);
  192. M++;
  193. delay(7000);
  194. comparacao();
  195. }
  196. delay(5000);
  197. bemvindo();
  198. }
  199.  
  200. void pbranco()
  201. {
  202. tft.setFont(&FreeSans9pt7b);
  203. tft.setTextColor(WHITE);
  204. tft.setTextSize(1);
  205. }
  206.  
  207. void ppreto()
  208. {
  209. tft.setFont(&FreeSans9pt7b);
  210. tft.setTextColor(BLACK);
  211. tft.setTextSize(1);
  212. }
  213.  
  214. void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
  215. {
  216. int16_t x1, y1;
  217. uint16_t wid, ht;
  218. tft.drawFastHLine(0, y, tft.width(), WHITE);
  219. tft.setFont(f);
  220. tft.setCursor(x, y);
  221. tft.setTextColor(GREEN);
  222. tft.setTextSize(sz);
  223. tft.print(msg);
  224. delay(10);
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement