Error with a simple function

Hello

I'm trying to learn how to use function in C++. I can't find the problem.

A simple function to calculate the Vol;t value from reading the ADC. On line 54, I'm getting different error like "Expected primary-expression before float or V_Value was not declare.

I tried many combinations, read many post, but still unresolved.

Martin

/*                       
 *          Rb 20K      /^
 * VCC------/\/\/\---/\/\/\-----GND
 *                    / 100k
  */
 

#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads;
int   adc0 = 0;
int   adc1 = 0;

float V_Out_0 = 0 ;
float V_Out_1 = 0;
float Vref = 3.29;
float Vout_0;
bool  Print_It = true;
long  NTC_Resistance = 0L;
long  Resistance = 0;
long  R_Pad =49800;  // Pad Resistance
float Celsius;
float Fahrenheit;

const float Kelvin = 273.15;

const float COF_A_Min= 0.2155502684E-03; // 11 C'   RES: 200000 
const float COF_B_Min= 2.863743926E-04; // 27.8 c'  RES: 88900
const float COF_C_Min= -1.054619151E-07; // 36.3 C' RES: 61400

const float COF_A_Mid= 1.060564221E-03; // 38.2 C'  RES: 57000    
const float COF_B_Mid= 1.679033187E-04; //58.7 C'   RES: 25600    
const float COF_C_Mid=  2.376857614E-07; // 73.3 C' RES: 15000

const float COF_A_UP= 1.500625598E-03; //75.7 C'    RES: 13700    
const float COF_B_UP= 0.6781413179E-04; // 124 c'   RES: 3670
const float COF_C_UP= 8.331333633E-07; // 150 C'    RES: 1830

float COF_A,COF_B,COF_C;

void setup() {
  Serial.begin(115200);
  pinMode(21,INPUT_PULLUP);   //I2C SDA
  pinMode(22, INPUT_PULLUP);  //I2C SCL
  ads.begin();
  delay(4000);
  }

void loop() {
  //Read ADC 0 and convert it to a voltage value

  adc0 = ads.readADC_SingleEnded(0);
  V_Out_0 = {float V_Value(adc0)};

  //Now get the Thermistor value
  Resistance = (V_Out_0 *  R_Pad)/(Vref - V_Out_0);
  

  //Get the proper coefficient
  Get_Coefficient(Resistance;
  
  if (Print_It) {PrintInfo();}
  delay(4000);
  
  //Now get the temperature related to the resistance using Steinhart 
  

  

void PrintInfo(){
  Serial.print("AIN0: ");
  Serial.print(adc0,5);
  Serial.print("\tV_Out_0: ");
  Serial.print(V_Out_0, 4);
  Serial.print("  Resistance: ");
  Serial.print(Resistance); 
  Serial.print ("  COF_A: " + String(COF_A));
  Serial.print (("  Celsius: ") + String(Celsius,1));
  Serial.println();  
}

 float V_Value(int adc_read){
   float VVALUE;
   VVALUE = (( adc_read *  0.1875)/1000);
   return VVALUE;
  }

void Get_Coefficient(long Resistance){
   if (Resistance <= 61400) {
      COF_A = COF_A_Min;
      COF_B = COF_B_Min;
      COF_C = COF_C_Min;
   }
  else if ((Resistance >61400) & (Resistance <=15000){
      COF_A = COF_A_Mid;
      COF_B = COF_B_Mid;
      COF_C = COF_C_Mid;
  }
  else if ((Resistance < 15000) {
      COF_A = COF_A_Max;
      COF_B = COF_B_Max;
      COF_C = COF_C_Max;
  }
}
}

  // Line 54:
  V_Out_0 = {float V_Value(adc0)};

You meant:
V_Out_0 = V_Value(adc0);

You already told the compiler that the value returned by the function V_Value() is 'float'.

Make sure you indent the code in the IDE (that's done by pressing ctrlT on a PC or cmdT on a Mac) ➜ you'll see that your brackets {} are not balanced (the loop function does not close where it needs to)

Using Indent: Thanks for the info. Indeed there was an error there.

Thanks

Learn lessons.
In C++ when a variable type is declare, don't repeat it
Use indent to find bracket relations
"and operator" is write "&&" in C++

Thank you John and J-M-L

Martin

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