Trying to read a Pressure sender and display it too a LCD eventually after i get this nailed ... Problem i have right now is i keep getting this error .....
sketch_sep20a:2: error: expected constructor, destructor, or type conversion before '=' token
Psi = (float(sensor1(analogRead(2))));
float sensor1(float RawADC)
{
float sensor1psi;
Serial.println(RawADC);
sensor1psi = (RawADC/1024.00)*5; //calculate actual voltage across the sensor
sensor1psi = (-.177 + sqrt(.03133-(4*-.0065*(.052-sensor1psi))))/-.013; //quadratic formula to get a more acurate reading based on the curve
sensor1psi = sensor1psi * 14.7; //convert from bar to PSI
return sensor1psi;
}
Also am i going in the right direction with the code ? Thanks
sensor1psi = (-.177 + sqrt(.03133-(4*-.0065*(.052-sensor1psi))))/-.013; //quadratic formula to get a more acurate reading based on the curve
sensor1psi = sensor1psi * 14.7; //convert from bar to PSI
A few other random comments: I'd suggest putting a leading zero on your decimals (-0.177). I think it makes them much easier to read, and makes your negative signs easier to associate with the number.
The second line is typically written as:
sensor1psi *= 14.7
This is because saying "x = x + y" (or times, or divided by, or minus) is such a common operation that shortcut operators have been defined. The operators are: += -= *= /=. There are other such operators for other operations like bitwise shifts and boolean logic (OR, AND, etc...) but those four are the most commonly used, I think.