Hello,
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).
#include <StopWatch.h>
StopWatch MypressureSW;
int analogPin = 0;
int fsrReading, fsrVoltage;
float val1 = 0;
float val2 = 0;
float totalTime;
void setup()
{
Serial.begin(9600);
pinMode(analogPin, INPUT);
}
void loop()
{
if(analogRead(analogPin) < 100)
{
;;
}
if(analogRead(analogPin) > 200)
{
pressureTime();
}
delay(1000);
}
void pressureTime()
{
MypressureSW.start();
val1 = MypressureSW.value();
Serial.print("Pressure Applied At: ");
Serial.println(val1);
delay(10);
if(analogRead(analogPin)<100)
{
MypressureSW.stop();
val2 = MypressureSW.value();
Serial.print("Pressure removed at: ");
Serial.println(val2);
totalTime = val2 - val1;
Serial.print("The total time of pressure applied is: ");
Serial.println(totalTime);
MypressureSW.reset();
}
}
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.
Seán