timer

On the train to school this morning I was thinking about timers.

A timer has two states: reset and release.

In reset, savedTime (i.e. the timer’s time) = ofGetElapsedTimeMillis();
In release, savedTime != Millis() so the savedTime can actually be allowed to grow.

What we wanted to do was to say if the camera doesn’t find a face for five seconds, turn a boolean to be false ( that boolean controls whether your face should be “substituted” or not).

Sounds pretty easy. What I had wrong was I said
if(!cam.found() && substitute ) {
savedTime = ofGetElapsedTimeMillis();
……
………
My thought was to start timing when cam.found() is false. The problem is savedTime = ofGetElapsedTimeMillis() doesn’t mean “start timing” …well actually only the very first time the program goes through update()..from then on, it means “reset”. Therefore if I put “reset” in !cam.found(), the timer never gets started. Instead, the reset should happen when camera CAN found a face. So the correct code:

if(cam.found() ) {
savedTime = currentTime //reset timer (i.e. no timing)
}
else if(!cam.found() && substitute) {
int timePassed = currentTime – savedTime;
if(timePassed > 5000) {
substitute = false;
}
}

This is a simple programming concept. I have done this in Arduino and Processing before but never needed to start timing with conditionals. Better late than never I guess.

06. March 2012 von yinliu
Categories: anything and nothing, Spatial Media | Leave a comment