I have to do this calculation which I do with the following source:
int analogPin = 0; // Pressure sensor connected to analog pin 0
long val = 0; // variable to store the read value
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop()
{
val = analogRead(analogPin); // read the input pin (getting value of around 840-860)
val = ( 1 - ( val/ 1013.25 ) ^ 0.19) ) / 22.558;
Serial.print("Value: ");
Serial.println(val);
delay(1000);
}
This line gives an error:
val = ( 1 - ( val/ 1013.25 ) ^ 0.19) ) / 22.558;
The error is:
In function 'void loop()':
error: invalid operands of types 'double' and 'double' to binary 'operator^
I hope someone can help to solve this. I am totally new to the Arduino.
humm, isn't your val variable declared as an integer? in te code you give it values like a float (with decimals). from what i read on the ard ref pages, arduino doesn't handle floats just char, int and long. anyone cares to comment? (and please help with my push button question!!)
The Arduino reference pages at Arduino - Home state:
Variables
Variables are expressions that you can use in programs to store values, like e.g. sensor reading from an analog pin. They can have various types, which are described below. Floating point variables and operations are not currently supported.
char
int
long
string
array
i know that the atmega168 has twice as much programming space as atmega8. the pin configuration is different. this web page has a datasheet on atmega168 -- Arduino Playground - ArduinoMini
Damn. It appears that the Arduino core is now small enough to support basic operations with floats. I'll update the reference according. Unfortunately, Arduino still doesn't support exponentiation, which I assume is what you're trying to do with the "^".
i know that the atmega168 has twice as much programming space as atmega8. the pin configuration is different. this web page has a datasheet on atmega168 -- Arduino Playground - ArduinoMini