Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 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. ppreto();
  144. tft.setCursor(20, 170);
  145. tft.print(TS1);
  146. tft.setCursor(20, 250);
  147. tft.print(TS2);
  148. pbranco();
  149. getTempSensor(sensor1);
  150. tft.setCursor(20, 170);
  151. tft.print(TS1);
  152. getTempSensor(sensor2);
  153. tft.setCursor(20, 250);
  154. tft.print(TS2);
  155. delay(500);
  156. if (TS1 <= TIP) {
  157. CP++;
  158. } if (TS2 <= TIM) {
  159. CM++;
  160. } if (TS1 >= TIP && TS2 >= TIM) {
  161. int X = CM + CP;
  162. int Y = CP/X;
  163. tft.fillScreen(BLACK);
  164. showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
  165. showmsgXY(0, 40, 1, &FreeSans9pt7b, "Resultado");
  166. pbranco();
  167. tft.setCursor(0,70);
  168. tft.print("A probabilidade de a");
  169. tft.setCursor(0,90);
  170. tft.print("mancha ser de origem");
  171. tft.setCursor(0,110);
  172. tft.print("cancerigena é:");
  173. tft.setCursor(0,130);
  174. if (Y < 0) {
  175. Y = 0;
  176. }
  177. tft.print(Y);
  178. tft.setCursor(20,130);
  179. tft.print("%");
  180. delay(10000);
  181. exit(0);
  182.  
  183. }
  184. delay(200);
  185. } while (EB1 == LOW);
  186. }
  187.  
  188. void resultado()
  189. {
  190. tft.fillScreen(BLACK);
  191. exit(0);
  192. }
  193.  
  194. void bemvindo()
  195. {
  196. tft.fillScreen(BLACK);
  197. showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
  198. showmsgXY(0, 40, 1, &FreeSans9pt7b, "Feira Industrial ETEC HAS");
  199. pbranco();
  200. tft.setCursor(0, 170);
  201. tft.print("Pressione o botao para medir");
  202. tft.setCursor(0, 190);
  203. tft.print("a temperatura inicial");
  204. EB1 = digitalRead(B1);
  205. if (EB1 == HIGH) {
  206. showmsgXY(0, 70, 1, &FreeSans9pt7b, "Temperatura inicial (pele)");
  207. showmsgXY(0, 110, 1, &FreeSans9pt7b, "Temperatura inicial (mancha)");
  208. sensors.requestTemperatures();
  209. pbranco();
  210. getTempSensor(sensor1);
  211. tft.setCursor(20, 90);
  212. float TIP = TS1;
  213. tft.print(TS1);
  214. getTempSensor(sensor2);
  215. tft.setCursor(20, 130);
  216. float TIM = TS2;
  217. tft.print(TS2);
  218. M++;
  219. delay(7000);
  220. comparacao();
  221. }
  222. delay(5000);
  223. bemvindo();
  224. }
  225.  
  226. void pbranco()
  227. {
  228. tft.setFont(&FreeSans9pt7b);
  229. tft.setTextColor(WHITE);
  230. tft.setTextSize(1);
  231. }
  232.  
  233. void ppreto()
  234. {
  235. tft.setFont(&FreeSans9pt7b);
  236. tft.setTextColor(BLACK);
  237. tft.setTextSize(1);
  238. }
  239.  
  240. void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
  241. {
  242. int16_t x1, y1;
  243. uint16_t wid, ht;
  244. tft.drawFastHLine(0, y, tft.width(), WHITE);
  245. tft.setFont(f);
  246. tft.setCursor(x, y);
  247. tft.setTextColor(GREEN);
  248. tft.setTextSize(sz);
  249. tft.print(msg);
  250. delay(10);
  251. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement