I hope someone can help me with a little bit of code here.
I am trying to time how long a pressure is applied to a FSR. So, I will start a stopwatch running when the pressure is applied (above a value of 200 and the analogRead), noting that time, and I want to note the time the stopwatch is finished, and I want it to finish when the pressure drops below a specific value (i.e. below 100 on the analogRead).
int analogPin = 0;
int fsrReading, fsrVoltage;
float val1 = 0;
float val2 = 0;
if(analogRead(analogPin) < 100)
if(analogRead(analogPin) > 200)
val1 = MypressureSW.value();
Serial.print("Pressure Applied At: ");
val2 = MypressureSW.value();
Serial.print("Pressure removed at: ");
totalTime = val2 - val1;
Serial.print("The total time of pressure applied is: ");
However, all I get on the Serial Monitor, when I apply a constant pressure is
Pressure Applied At: 0.00
Pressure Applied At: 2037.00
Pressure Applied At: 3076.00
Pressure Applied At: 4115.00
And when I let go, it just sits with that information. So, it seems it isn't reading the time when I let the pressure go.
I imagine I am doing something obvious and silly, but I can't see it.
Thanks in advance.