- Mon Jan 03, 2011 7:45 pm
#116549
I'm very new to the Ardruino, but I believe I'm starting to learn the code. I have two MXP4115 pressure sensors, and one slide potentiometer. I'd like to take these inputs, capture the elapsed time between each iteration, then run a calculation to get a result. Hopefully that makes sense. Does the following code look correct?
/* Taking input from 3 analog sensors, two MPX 4115 pressure sensors, and simple slide potentiometer, to calculate an estimated result, which uses elapsed time to get a rate */
const int analogpinP1 = 1; // Analog input at pin 1 is "P1"
const int analogpinP2 = 2; // Analog input at pin 2 is "P2"
const int analogpinP3 = 3; // Analog input at pin 3 is "P3"
void setup()
{
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
int adcvalue1 = analogRead(analogpinP1); // read the analog in value for P1:
long pressure1 = 950 + adcvalue1 / 8.5; //convert it to milli bars
int adcvalue2 = analogRead(analogpinP2); // read the analog in value for P2:
long pressure2 = 950 + adcvalue2 / 8.5; //convert it to milli bars
int adcvalue3 = analogRead(analogpinP3); // read the analog in value for P3:
long position = 12.3 + adcvalue3 / 0.5; //convert it to inches
time = micros();
elapsedtime = micros() - time;
long result = ((pressure1 + pressure2)^(1.0/2.0))/(position^2)*elapsedtime+7.2853; // calculate result
Serial.print("\t result = ");
Serial.print(result); // print result
delay(10);
}
/* Taking input from 3 analog sensors, two MPX 4115 pressure sensors, and simple slide potentiometer, to calculate an estimated result, which uses elapsed time to get a rate */
const int analogpinP1 = 1; // Analog input at pin 1 is "P1"
const int analogpinP2 = 2; // Analog input at pin 2 is "P2"
const int analogpinP3 = 3; // Analog input at pin 3 is "P3"
void setup()
{
Serial.begin(9600); // initialize serial communications at 9600 bps:
}
void loop()
{
int adcvalue1 = analogRead(analogpinP1); // read the analog in value for P1:
long pressure1 = 950 + adcvalue1 / 8.5; //convert it to milli bars
int adcvalue2 = analogRead(analogpinP2); // read the analog in value for P2:
long pressure2 = 950 + adcvalue2 / 8.5; //convert it to milli bars
int adcvalue3 = analogRead(analogpinP3); // read the analog in value for P3:
long position = 12.3 + adcvalue3 / 0.5; //convert it to inches
time = micros();
elapsedtime = micros() - time;
long result = ((pressure1 + pressure2)^(1.0/2.0))/(position^2)*elapsedtime+7.2853; // calculate result
Serial.print("\t result = ");
Serial.print(result); // print result
delay(10);
}