#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#define BLACK 0x0000
#define RED 0xF800
#define WHITE 0xFFFF
#define GREEN 0x07E0
#define DARKGREEN 0x03E0
#define DARKGREY 0x7BEF
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
MCUFRIEND_kbv tft;
float roomTemp;
float objectTemp, stemp;
int readcount = 0;
int threshold = 0;
// ULTRASONIC SENSOR PREPARATION
#define echoPin 11
#define trigPin 12
int maximumRange = 25;
int minimumRange = 15;
long distance;
long duration;
int dtime;
void setup()
{
uint16_t ID = tft.readID();
tft.begin(ID);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
tft.begin();
delay(1000);
tft.setTextColor(WHITE);
}
void loop()
{
digitalWrite (trigPin, LOW);
delayMicroseconds (2);
digitalWrite (trigPin, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
objectTemp = threshold + mlx.readObjectTempC();
roomTemp = mlx.readAmbientTempC();
Serial.println("Object:" + String(objectTemp) + ", Ambient:" + String(roomTemp));
Serial.println(distance);
tft.setTextSize(1);
tft.setCursor(0, 25);
tft.print("Dis:" + String(distance) + "cm");
tft.setCursor(65, 25);
tft.print("Room:" + String(roomTemp).substring(0, 4) + "C");
tft.setTextSize(2);
tft.setCursor(0, 0);
if (distance > maximumRange)
{
tft.print("GET CLOSER");
}
if (distance < minimumRange)
{
tft.print("TOO CLOSE!");
}
if (readcount == 5)
{
distemp();
}
else
{
tft.print("HOLD ON");
stemp = stemp + objectTemp;
readcount++;
dtime = 200;
}
}
else{
dtime = 100;
readcount = 0;
stemp = 0;
}
delay(dtime);
tft.println("count :" + String(readcount));
void distemp()
{
objectTemp = stemp / 5;
tft.setTextSize(1);
tft.print("YOUR TEMP:");
tft.setTextSize(2);
tft.setCursor(60, 5);
tft.print(String(objectTemp).substring(0, 4) + "C");
readcount = 0;
stemp = 0;
if (objectTemp >= 37.5)
{
play_alert();
}
else
{
play_ok();
}
dtime = 5000;
}
void play_ok()
{
tone (3, 600, 1000);
delay (200);
tone (3, 750, 500);
delay (100);
tone (3, 1000, 500);
delay (200);
noTone(3);
}
void play_alert()
{
tone (3, 2000, 1000);
delay (1000);
tone (3, 3000, 100);
delay (1000);
tone (3, 4000, 1000);
delay (1000);
noTone(3);
}
Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"
02-22-22:91:5: error: expected unqualified-id before 'else'
** else{**
** ^~~~**
02-22-22:97:14: error: expected constructor, destructor, or type conversion before '(' token
** delay(dtime);**
** ^**
02-22-22:98:9: error: 'tft' does not name a type
** tft.println("count :" + String(readcount));**
** ^~~**
exit status 1
expected unqualified-id before 'else'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.