Using a Force Sensing Resistor and time input

So the code below measures how much force is exerted on the FSR. I would like to know what would I have to change in this code so that it can record for how long the FSR is being pressed for. So instead of “What force is exerted on the FSR?”, I want to ask “How long is the FSR being pressed for?”

Any help will be most appreciated

#include <Wire.h>
SoftwareSerial bluetooth_port(0, 1); //ports for Rx and Tx
int flexSensorPin; // The flex sensor for pin 0 

void setup() 

  Serial.begin(9600); // Start the serial transmission

void loop() 

  flexSensorPin = analogRead(A0); // Flex sensor pin 



Look for state change detection (there's an example in the IDE).

In your case: pressed if the analog reading is higher (or smaller, depending on your wiring) than a certain threshold. Record the value of millis() when it goes from unpressed to pressed, and see how long it's been (compare to the then current value of millis()) whne it goes from pressed to unpressed.