Trigger event based on elapsed time since float changes?

Hello there

I’m working on a program that is detecting movement via a webcam. I’m comparing frames to trigger certain events based on code I found in this thread. For example:

  
if (activityMonitor >= 30) {  
  
things happen  
  
}  

I would like to trigger another event that will happen depending on how long the activityMonitor float value has been < 30.

I’m not too sure how to do this - I think that I need to subtract the time that my activityMonitor float drops below 30 from the elapsed time of the app (ofGetElapsedTimeMillis() ?). I’m unsure how to get the time that the float drops.

So to summarise I want it to work in the same way that a computer screensaver does - if there is no movement for x amount of time then my event is triggered.

Any ideas or links to things that might help me would be much appreciated.

Many thanks

Michael

try thinking about it like this:

you have two possible states for input:

  • there is enough movement now
  • there is not enough movement now

you want to know when there has continuously been enough movement for the last n seconds, let’s say 5 seconds. well, another way of saying this is that you want to know how long ago there was not enough movement was more than 5 seconds ago.

ofGetElapsedTimef() returns a number that is always increasing since the program was started. so what you can do is, every time there is not enough movement, you store ofGetElapsedTimef(); and every time there is enough movement, you look at ofGetElapsedTimef() and compare it to your stored number: if the stored number is more than 5.0f (5 seconds) smaller than the current time, then you’ve had enough movement for 5 seconds and you’re good to go.

Thanks damian, but i have been looking to that elapsedtime in seconds, the problem is i don’t know how to store the elapsed time at an exact time…
know my “stopwatch” look like this:
if( openMov == 0 ){
time = ofGetElapsedTimef();
if( time > (time + 15) ){
openMov = 1;
}

(it just part of the code)
And this is not right… what i need is to store…!?
Johanne

Hi Johanne - you are replying to the wrong thread!
This thread is about motion based triggers.

but to answer your question:

as damian said - you can just store the time whenever openMov != 0 - then when it does = 0 you can compare the current time to the stored time.

ie:

  
if( openMov != 0 ){  
   time = ofGetElapsedTimef();  
}else{  
    if( ofGetElapsedTimef() - time > 15 ){  
       openMov = 1;  
    }  
}  

Thanks Damian

That makes complete sense to me, I think I was tired and not thinking straight. I’ll try it out.

Another problem that has just popped up is that I’m getting this error.

  
ofSoundPlayer: Could not load sound file  

No idea why. I do have quite a lot going on in the application. Does anyone know if ofSoundPlayer stops working if there’s too much happening in the app (6/7 particle systems)?

Thanks again!

Michael