X > Value for 2 sec, problem

PeterH:
Write some code that does your pixelly comparison stuff and just returns a true/false value.
Now you're just looking for the result to remain true for longer than two seconds.

Which of these parts of the problem have you solved?

Can the problem boil down to this;

ReTrig the LED for 2 more secs if the count>4

All programm/fuctions/LCD printing with interupts all are working.

The only thing that doesnt work is that part where mode turns from B to F and F to B. Its the same idea with the :
http://volatilebit.com/electronics/minor-arduino/item/11-press-hold-switch-arduino

The diff is that i dont have switch, sum_back > 4 works as a switch for me. State is changing when i place he object on position, but is if let it there .. state continues to changing repeatable

From the video/led youtube example I understamnd that the buttom must be pressed/held for a minimum time to toggle the output.
I cannot clearly see how this relates to your problem. (sorry)

I tried this code. Got a stedy ledON (sum_back > 4, not changing)

int HOLD_DELAY = 1000;
int last_back,sum_back;
unsigned long start_hold;
boolean allow = false;
byte led=13;
char mode;

void setup()
{ pinMode(led,OUTPUT); }

void loop()
{
    sum_back=0;
    for(int i=40;i<46;i++) for(int j=45;j<46;j++)  sum_back += 1; // cam.getPixel(&f_data,i,j); // count the tracked pixels
    
    if(sum_back>4 && last_back==0)    // for pixels > 4 , mark the time , allow mode state changes ..
    {
      start_hold=millis();
      allow = true;
    } 
    if(allow==true && sum_back>4 && last_back>4)             //if pixels remains > 4 , for longer than 2 sec .. change state of mode and prevent multiple state changes
      if((millis()-start_hold) >= HOLD_DELAY)
      {
        if(mode=='F') mode='B'; else mode='F'; 
        allow = false;      
      }
    last_back=sum_back;
    digitalWrite(led,mode=='F');
    delay(300);
}

knut_ny:
From the video/led youtube example I understamnd that the buttom must be pressed/held for a minimum time to toggle the output.

Yeah but if you keep pressing the button the led must not keep changing states. The only way to change state must be to let it first and then re-press it for 2 sec. In my case i put an object for 2sec and is mode is F becomes B...is i continues to keep it there for more that those 2 sec it must not change again. Must move away the object and put it again to go ftom B to F..

Legolas69:
The only thing that doesnt work is that part where mode turns from B to F and F to B.

Have you read the last paragraph of Reply #12? It describes an algorithm to do what you're asking for.

When I run this example, it seems to work exactly like the video.

int HOLD_DELAY = 1000;
int last_back,sum_back;
unsigned long start_hold;
boolean allow = false;
byte led=13;
char mode;

void setup()
{ pinMode(led,OUTPUT); pinMode(3,INPUT_PULLUP);}

void loop()
{
    sum_back=digitalRead(3)*5;
    //for(int i=40;i<46;i++) for(int j=45;j<46;j++)  sum_back += 1; // cam.getPixel(&f_data,i,j); // count the tracked pixels
    
    if(sum_back>4 && last_back==0)    // for pixels > 4 , mark the time , allow mode state changes ..
    {
      start_hold=millis();
      allow = true;
    } 
    if(allow==true && sum_back>4 && last_back>4)             //if pixels remains > 4 , for longer than 2 sec .. change state of mode and prevent multiple state changes
      if((millis()-start_hold) >= HOLD_DELAY)
      {
        if(mode=='F') mode='B'; else mode='F'; 
        allow = false;      
      }
    last_back=sum_back;
    digitalWrite(led,mode=='F');
    delay(300);
}

PeterH:
Have you read the last paragraph of Reply #12? It describes an algorithm to do what you're asking for.

read but ddint understand 100%

the testprog above ran perfectly the way I believe you have asked for.
When i changes input low->hi the ouput changed with a second delay

Yeah its working, i ran it too. Seems the problem is when count the sum_back.. maybe the interupt effect it?

EUREKA ??
There is a dead rat somwhere. try cli/sei wrapped aroud your counting. (may fuck up somthing, but worth trying)

we used the interrupts(), nointerrupts() to this part of code and still dont work.. its realy makes me headache

Ok so after many tests and changing i end to this program:

    sum_back=0;
     for(int i=40;i<46;i++)
    {
      for(int j=39;j<41;j++)
      {
        pixel = cam.getPixel(&f_data,i,j);                    // count the tracked pixels
        if(pixel==1)
        {
         sum_back++;
        }
      }
    }
  
    if(sum_back > 4 && last_back==0 )                // for pixels > 4 , mark the time , allow mode state changes ..
    {
      start_hold=millis();
      allow = true;
    }
     
    if(sum_back > 4 && allow == true && last_back > 4 )             //if pixels remains > 4 , for longer than 2 sec .. change state of mode and prevent multiple state changes
    {
      if((millis()-start_hold) > HOLD_DELAY)
      {
//        if(mode=='F')
//        {
//          mode='B';
//        }
//        else if(mode=='B')
//        {
//         mode='F'; 
//        }

    if(ledState == LOW) 
    {
      ledState = HIGH;
    } 
    else 
    {
      ledState = LOW;
    }
    
    digitalWrite(led, ledState);
    
    allow = false;  
      }
   }
    
    last_back=sum_back;

Problem is that randomly when i keep the object on tracking position it may change the state of LED, i must stay as be.
Seems is something with the interupts but even if i use noInterrupts() etc .. problem still randomly exists.
Code is right, cant understand what goes wrong