LED and FSR sensors, setting a timer to an LEDS

Hey guys so I'm trying to write a program where I have a FSR sensor as my input and an LED as an output, my LED lights up when the FSR gets into a certain range and goes off when it is out of that range. Now what im trying to do is to set a timer so that if the sensor is within that specific range for a certain amount of time the LED with turn off. I started out trying to use the millis() function but failed and now i am stuck with what to do next. I can post my code if someone asks to show what I have done so far. Thank you

That seems easy enough.

You could accomplish that with basically a "flag", as I call it, and a timer.

I threw together this code to show you some of the tricks you could use.

int LED = 10;
int FSR = A1;
int LEDstate;
int forceValue;
int threshold = 200; // or whatever value
int oldFlag;
int newFlag;
int thresholdFlag;
long thresholdTimer;
int thresholdDelay = 1000; // or however long

void setup()
{
  pinMode(FSR, INPUT);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
}
void loop()
{
 oldFlag = thresholdFlag;
 forceValue = analogRead(FSR);
 if (forceValue >= threshold)
 {
   thresholdFlag = 1;
 }
 else
 {
   thresholdFlag = 0;
 }
 newFlag = thresholdFlag;
 if (oldFlag == 0 && newFlag == 1)
 {
   thresholdTimer = millis();
   LEDstate = 1;
 }
 else if (oldFlag == 1 && newFlag == 0)
 {
   LEDstate = 0;
 }
 
 if (millis() > thresholdTimer + thresholdDelay && thresholdFlag == 1)
 {
   LEDstate = 0;
 }
 
 digitalWrite(LED, LEDstate);
}

Keep in mind that I just threw this together and have nothing to test this on. There may be an even simpler method but I'm no expert. It should give you some insight though.

If you're still having trouble tomorrow, I think I have a FSR lying around and could put together a simple test to help out.