Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Bibliotecas
- #include <Wire.h> //Comunicacao I2C
- #include <Adafruit_GFX.h> //Graficos
- #include <MCUFRIEND_kbv.h> //Hardware ST7735
- #include <OneWire.h>
- #include <DallasTemperature.h>
- //DS18B20
- #define ONE_WIRE_BUS 19
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- uint8_t sensor1[8] = { 0x28, 0xF4, 0x67, 0x79, 0x97, 0x10, 0x03, 0x97 };
- uint8_t sensor2[8] = { 0x28, 0x92, 0x96, 0x79, 0x97, 0x10, 0x03, 0x8D };
- //TFT
- MCUFRIEND_kbv tft; //Indicar para a biblioteca o TFT
- #include <Fonts/FreeSans9pt7b.h>
- #include <Fonts/FreeSans12pt7b.h>
- #include <Fonts/FreeSerif12pt7b.h>
- #include <FreeDefaultFonts.h>
- #define BLACK 0x0000
- #define RED 0xF800
- #define GREEN 0x07E0
- #define WHITE 0xFFFF
- #define GREY 0x8410
- //Botoes
- #define B1 21 //Botao1
- int EB1; //Estado do B1
- //Variaveis
- int M; //Menu
- float TS1; //Temperatura do S1
- float TS2; //Temperatura do S2
- float TIP;
- float TIM;
- int CP;
- int CM;
- int RR;
- void setup(void)
- {
- Serial.begin(9600); //Comunicacao serial em 9600baud
- uint16_t ID = tft.readID(); //16 bits para a leitura do TFT
- if (ID == 0xD3) ID = 0x9481; //ID do ST7735
- sensors.begin();
- tft.begin(ID); //Inicia a comunicacao com o ST7735
- tft.setRotation(0); //Rotacao para portrato
- pinMode(B1, INPUT);
- }
- void loop(void)
- {
- bemvindo();
- delay(1000);
- }
- void getTempSensor(DeviceAddress deviceAddress)
- {
- float a = sensors.getTempC(deviceAddress);
- if (deviceAddress == sensor1) {
- TS1 = a;
- } if (deviceAddress == sensor2) {
- TS2 = a;
- }
- }
- void comparacao()
- {
- tft.fillScreen(BLACK);
- showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
- showmsgXY(0, 40, 1, &FreeSans9pt7b, "Comparacao");
- pbranco();
- tft.setCursor(0, 80);
- tft.print("Esfrie a area do exame.");
- tft.setCursor(0, 100);
- tft.print("Pressione o botao para");
- tft.setCursor(0, 120);
- tft.print("prosseguir");
- EB1 = digitalRead(B1);
- if (EB1 == HIGH) {
- M = 2;
- delay(2000);
- calculo();
- } else {
- delay(5000);
- comparacao();
- }
- }
- void calculo()
- {
- tft.fillScreen(BLACK);
- showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
- showmsgXY(0, 40, 1, &FreeSans9pt7b, "Comparacao");
- showmsgXY(0, 70, 1, &FreeSans9pt7b, "Estado");
- showmsgXY(0, 110, 1, &FreeSans9pt7b, "Temperatura inicial (pele)");
- showmsgXY(0, 150, 1, &FreeSans9pt7b, "Temperatura da pele");
- showmsgXY(0, 190, 1, &FreeSans9pt7b, "Temperatura inicial (mancha)");
- showmsgXY(0, 230, 1, &FreeSans9pt7b, "Temperatura da mancha");
- pbranco();
- tft.setCursor(20, 90);
- tft.print("Aperte o botao para iniciar");
- tft.setCursor(20, 130);
- float TIP = TS1;
- tft.print(TIP);
- tft.setCursor(20, 210);
- float TIM = TS2;
- tft.print(TIM);
- EB1 = digitalRead(B1);
- if (EB1 == HIGH)
- {
- diferenca();
- }
- delay(5000);
- calculo();
- }
- void diferenca()
- {
- tft.fillScreen(BLACK);
- showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
- showmsgXY(0, 40, 1, &FreeSans9pt7b, "Comparacao");
- showmsgXY(0, 70, 1, &FreeSans9pt7b, "Estado");
- showmsgXY(0, 110, 1, &FreeSans9pt7b, "Temperatura inicial (pele)");
- showmsgXY(0, 150, 1, &FreeSans9pt7b, "Temperatura da pele");
- showmsgXY(0, 190, 1, &FreeSans9pt7b, "Temperatura inicial (mancha)");
- showmsgXY(0, 230, 1, &FreeSans9pt7b, "Temperatura da mancha");
- pbranco();
- tft.setCursor(20, 90);
- tft.print("Calculando...");
- tft.setCursor(20, 130);
- float TIP = TS1;
- tft.print(TIP);
- tft.setCursor(20, 210);
- float TIM = TS2;
- tft.print(TIM);
- delay (500);
- EB1 = digitalRead(B1);
- do {
- sensors.requestTemperatures();
- ppreto();
- tft.setCursor(20, 170);
- tft.print(TS1);
- tft.setCursor(20, 250);
- tft.print(TS2);
- pbranco();
- getTempSensor(sensor1);
- tft.setCursor(20, 170);
- tft.print(TS1);
- getTempSensor(sensor2);
- tft.setCursor(20, 250);
- tft.print(TS2);
- delay(500);
- if (TS1 <= TIP) {
- CP++;
- } if (TS2 <= TIM) {
- CM++;
- } if (TS1 >= TIP && TS2 >= TIM) {
- int X = CM + CP;
- int Y = CP/X;
- tft.fillScreen(BLACK);
- showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
- showmsgXY(0, 40, 1, &FreeSans9pt7b, "Resultado");
- pbranco();
- tft.setCursor(0,70);
- tft.print("A probabilidade de a");
- tft.setCursor(0,90);
- tft.print("mancha ser de origem");
- tft.setCursor(0,110);
- tft.print("cancerigena é:");
- tft.setCursor(0,130);
- if (Y < 0) {
- Y = 0;
- }
- tft.print(Y);
- tft.setCursor(20,130);
- tft.print("%");
- delay(10000);
- exit(0);
- }
- delay(200);
- } while (EB1 == LOW);
- }
- void resultado()
- {
- tft.fillScreen(BLACK);
- exit(0);
- }
- void bemvindo()
- {
- tft.fillScreen(BLACK);
- showmsgXY(0, 20, 1, &FreeSans9pt7b, "Scanner de Melanoma v0.5i");
- showmsgXY(0, 40, 1, &FreeSans9pt7b, "Feira Industrial ETEC HAS");
- pbranco();
- tft.setCursor(0, 170);
- tft.print("Pressione o botao para medir");
- tft.setCursor(0, 190);
- tft.print("a temperatura inicial");
- EB1 = digitalRead(B1);
- if (EB1 == HIGH) {
- showmsgXY(0, 70, 1, &FreeSans9pt7b, "Temperatura inicial (pele)");
- showmsgXY(0, 110, 1, &FreeSans9pt7b, "Temperatura inicial (mancha)");
- sensors.requestTemperatures();
- pbranco();
- getTempSensor(sensor1);
- tft.setCursor(20, 90);
- float TIP = TS1;
- tft.print(TS1);
- getTempSensor(sensor2);
- tft.setCursor(20, 130);
- float TIM = TS2;
- tft.print(TS2);
- M++;
- delay(7000);
- comparacao();
- }
- delay(5000);
- bemvindo();
- }
- void pbranco()
- {
- tft.setFont(&FreeSans9pt7b);
- tft.setTextColor(WHITE);
- tft.setTextSize(1);
- }
- void ppreto()
- {
- tft.setFont(&FreeSans9pt7b);
- tft.setTextColor(BLACK);
- tft.setTextSize(1);
- }
- void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
- {
- int16_t x1, y1;
- uint16_t wid, ht;
- tft.drawFastHLine(0, y, tft.width(), WHITE);
- tft.setFont(f);
- tft.setCursor(x, y);
- tft.setTextColor(GREEN);
- tft.setTextSize(sz);
- tft.print(msg);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement