I have a code for 6 pin FSR sensor .
from that I can read the pressure and it give the output in reading and LED . I combined 3pin in one red LED and 3 pin in another green LED .
Now I need to calculate the time how long the pressure sensor is pressed? I need to add the code for the calculation of time in my code.
The Arduino State Change Example shows you how to do that.
Detect when the sensor becomes pressed, record the time in milliseconds, detect when it becomes released, note the finish time and subtract start from finish.
what code should i add and where to add the code ? for note the time can I get the time to be displayed while pressing the FSR and not display the time while FSR is released?
Forum members are happy to help you solve specific problems with your code. Study the Blink without Delay example to learn how to use the millisecond timer, and the State Change example already mentioned.
If you want someone to write code for you, you are welcome to post on the Jobs and Paid Collaboration forum section, but be prepared to pay for the help.
C:\Users\Lan\AppData\Local\Temp.arduinoIDE-unsaved20231013-19492-1vnshac.biifi\sketch_nov13a\sketch_nov13a.ino: In function 'void loop()':
C:\Users\Lan\AppData\Local\Temp.arduinoIDE-unsaved20231013-19492-1vnshac.biifi\sketch_nov13a\sketch_nov13a.ino:33:7: error: 'printHumanReadableTime' was not declared in this scope
printHumanReadableTime(startDetectionTime);
^~~~~~~~~~~~~~~~~~~~~~
exit status 1
Compilation error: 'printHumanReadableTime' was not declared in this scope
Here is a way to use the state change detection method on an analog input. It features hysteresis so that the output does not chatter around the threshold. This code uses an LDR to turn a light on when it gets dark.
// turn light on when it gets dark
const byte sensorPin = A0;
const byte ledPin = 13;
const int threshold = 500;
const int hysteresis = 50;
bool sensorState;
bool lastSensorState = true;
void setup()
{
Serial.begin(115200);
Serial.println("analog state change demo");
pinMode(sensorPin, INPUT_PULLUP); // internal pullup as LDR load resistor
pinMode(ledPin, OUTPUT);
}
void loop()
{
int sensorReading = analogRead(sensorPin);
// Is sensor output higher or lower than treshold?
if (sensorReading < threshold - hysteresis)
{
sensorState = true; // higher
}
else if (sensorReading > threshold + hysteresis)
{
sensorState = false; // lower
}
// has the state changed?
if (sensorState != lastSensorState)
{
// did the state change low to high?
if (sensorState == false)
{
Serial.println("light on");
digitalWrite(ledPin, HIGH);
}
// the state changed high to low
else
{
Serial.println("light off");
digitalWrite(ledPin, LOW);
}
lastSensorState = sensorState;
}
}
An Arduino has no system time. The closest to that would be the millis() function, which gives the number of milliseconds from starting up your board, rolling over to zero every 49 days. Serial.println(millis());