Hello everybody,
I'm working on a university project that involves using an Arduino Uno to get data from a pressure transducer. I need a program that records the times at two different value of pressure. Here the code I wrote:
#include <Time.h>
void setup() {
// put your setup code here, to run once:,
Serial.begin(9600); //start talking with the computer. 9600 just tells the rate.
setTime(12,05,55,01,12,2017);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(A0);
float Pressure = sensorValue/5.637;
time_t t1=0;
time_t t2=0;
float Pstart;
float Pend;
int P1;
int P2;
int DeltaT;
P1=20;
P2=65;
if (Pressure<=P2+2){
Serial.println(Pressure);
if ((Pressure>=P1) && (Pressure<P1+1)){
t1=now();
Pstart=Pressure;
}
if ((Pressure>=P2) && (Pressure<P2+1)){
t2=now();
Pend=Pressure;
}
DeltaT=t2-t1;
}
else if (Pressure>P2+2)
{
Serial.println("DeltaT=");
Serial.println(DeltaT);
Serial.println("P1=");
Serial.println(Pstart);
Serial.println("P2=");
Serial.println(Pend);
}
//exit(0);
//delay (2000);
Basically the program reads the pressure until it reachs a specific value then it has to print the time passed between P1 and P2. The problem is that no matter what I do or change but the value DeltaT printed is always egual to zero.
I hope I wrote everything necessary to understand my problem. Thanks!