Noob with errors

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

You need to post all of your code. That snippet is not enough for us to identify the problem.

Also when you post it do it correctly the code tab is the one next to the quote tab.

float there is not a function, it is a cast. The proper syntax is psi = (float)sensor1(...);

PaulS:
You need to post all of your code. That snippet is not enough for us to identify the problem.

That is all i have so far , Had a feeling that i was missing something :frowning:

Grumpy_Mike:
Also when you post it do it correctly the code tab is the one next to the quote tab.

Sorry sorted now mate thanks

KeithRB:
float there is not a function, it is a cast. The proper syntax is psi = (float)sensor1(...);

Cheers mate

jordan172:

PaulS:
You need to post all of your code. That snippet is not enough for us to identify the problem.

That is all i have so far , Had a feeling that i was missing something :frowning:

Start here -

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.

Kudos on your comments.

float there is not a function, it is a cast. The proper syntax is psi = (float)sensor1(...);

Actually, it is:

Rubbish function, in my opinion. But, then, I'm not in charge.