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