Can anyone help me solve the errors?

#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.

Make sure you indented the code in the IDE, that's done by pressing ctrlT on a PC or cmdT on a Mac)

You'll see that you have an wrongly placed closing } in the loop (line 90), which makes some of the code fall out any function.

image

if you fix this you'll still have other challenges, make sur all your else are attached to an if and that () and {} are balanced

NOW THIS IS THE ERROR

#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"

C:\Users\user\Documents\Arduino\02-22-22\02-22-22.ino: In function 'void loop()':

02-22-22:90:3: error: 'else' without a previous 'if'

** else {**

** ^~~~**

exit status 1

'else' without a previous 'if'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

  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;
  }

You can only have one 'else' per 'if'. You can have multiple 'elseif's but only one 'else'. Not too sure of your logic, maybe you needed nested if/else statements to achieve what you were going for?

You can't have an 'else {} else {}'. You can only put an 'else' on an 'if': 'if () {} else {}'

yes, as I said above

how about this one?

Arduino: 1.8.19 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Sketch uses 26944 bytes (10%) of program storage space. Maximum is 253952 bytes.

Global variables use 622 bytes (7%) of dynamic memory, leaving 7570 bytes for local variables. Maximum is 8192 bytes.

avrdude: verification error, first mismatch at byte 0x036c

** 0x30 != 0x70**

avrdude: verification error; content mismatch

avrdude: verification error; content mismatch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

initially you were compiling for a UNO and now for a MEGA....

which board do you have?

mega 2560 sir

did you check the common issues?

yes sir. i already checked

what did the loopback test show?

Did you

  1. Check that your USB cable is working. Test it with a different device, or try using a different USB cable. Make sure it is a data cable, a charge-only cable will not work.

Or a different USB gazinta, or with or without a hub &c.

Also not mentioned or I didn't see it is to reboot your machine.

It's probably the only reason I ever have to… I can go weeks with no trouble, other times right away but sometimes my USB ports become, one by one, locked out unavailable.

I have found no other way to force the USB subsystem to reset itself.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.