Unqualified-id before '.' token

Hi , i try to include my own header to the main code. However it always show unqualified-id token'.' at temperature.begin() and temperature.calculate_temperature(). Could you guy give me advice on my issue/

main code


#include <Arduino.h>
#include "temperature.h"

void setup() {
  
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  temperature.begin();
}

void loop() {
  temperature.calculate_temperature();
  delay(10); // this speeds up the simulation
}

temperature.h :

#ifndef temperature_h
#define temperature_h



class temperature {
  public:
  void begin();
  void calculate_temperature();
    

};

#endif 





temperature.cpp :

#include "temperature.h"
#include <Arduino.h>
#define Temp_sense 21


void temperature::begin(){
 pinMode(Temp_sense,INPUT);
  
}


void temperature::calculate_temperature(void){

   const float BETA = 3950; 
   int analogValue = analogRead(Temp_sense);
   float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
   Serial.println(celsius);
   
}

You have a class named temperature but no object of that class

As @UKHeliBob said... you need to first define an object of type "temperature"... and then you can use the methods on that object.

In the example below (I've just put all your code in one program), first we define an object... and then you can use it.

// ---------- Class declaration ---------------

#include <Arduino.h>
#define Temp_sense 21

class temperature 
{
  public:
  void begin();
  void calculate_temperature();
};

// ----------- Class definition -------------
void temperature::begin()
{
 pinMode(Temp_sense,INPUT);  
}

void temperature::calculate_temperature(void)
{
   const float BETA = 3950; 
   int analogValue = analogRead(Temp_sense);
   float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
   Serial.println(celsius);  
}


// --------- Main program -----------------

#include <Arduino.h>

temperature Temperature;      // <<<<<<< You need to define a "temperature" object.

void setup() {
  
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  Temperature.begin();        // Note upper case T (the object you defined above)
}

void loop() 
{
  Temperature.calculate_temperature();     // Note upper case T (the object you defined above)
  delay(10); // this speeds up the simulation
}
1 Like

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