Create a delay (ofGetElapsedTime())

Hello everyone !

I’m a little bit lost in my code, and maybe, i make a mistake… Can you help me about it ?

It is about making a delay: I use a leapMotion, but the leap’s detection is really too fast for every command. And i’m trying something like:

if ((simpleHands[i].fingers.size() == 1) && (Act.timeApp == true)) {
// do the thing
}

Act.timeApp is like this (time is ofGetElapsedTime() ):

if ( DelayApp == false) {
    e = time + 2.00 ; /// Time + 2 seconds
    DelayApp = true;
    cout << "TADAAAAA"<<endl;
}

if ( e > time){
    timeApp = false;
}else{
    timeApp = true;
}

Am I rigth ?

Thank you for every answer, it will help me so much (because it is a little mess at this time).

Thank you again !

Vincent

PS: i also try something like this :

if (DelayApp == false) {

    for (int e; e < 200; e++) {
        cout << "you can move in" << 200 - e << endl;
        if( e == 200){
            DelayApp = true;
        }
    }
}    

Hey

I think your approaching the delay in the wrong way. I would have flag (boolean variable) that you set from your leapmotion code and use this to control whether the next routine should run.

i.e. something like this

bool isDoingTheThing = false;

if (!isDoingTheThing && (simpleHands[i].fingers.size() == 1) && (Act.timeApp == true)) {
// do the thing and run the routine
  isDoingTheThing = true;
   doTheThiing();
}

void testApp::doTheThiing() {
  // do whatever you need to here

 ////.... once it is done and you can allow the routine to run again reset your flag
 isDoingTheThing = false;
}

Hey !

Thank you for your answer, but, sorry, i forgot to tell you: I am trying to have a delay between different Leap things, like :

if ((simpleHands[i].fingers.size() == 1) && (Act.timeApp == true)) {
// do the thing
} 
if ((simpleHands[i].fingers.size() == 2) && (Act.timeApp == true)) {
// do an orther thing
}

The problem is : i want to have a delay between this two commands, because they happen too quickly :frowning:

But thank you very much for this answer.

Vincent

Maybe you can try not to update from leap on every frame.

if (ofGetFrameNum()%60 == 0) {
     // Do something only every 60 frames
}

You tell me, i need to make something like :

if (simpleHands[i].fingers.size() == 1) {
ofGetFrameNum()%60 // to slow down
}
if (simpleHands[i].fingers.size() == 2) {
ofGetFrameNum()%1 // to make it faster
}

It is like slowing down the leap? it can be perfect! :smiley:
Thank you very much, i will try it now (told me if i’m wrong, i think i will see it soon)!

V.

Finally i just change the frameRate with ofSetFrameRate(5);
And it works perfectly !

I hope, it’s a good method…

What you “slow down” that way is the reading of the data leap is sending I guess.

if (ofGetFrameNum()%60 == 0) {
     // The code here instead of being executed on every frame is executed every 60 frames.
    if (simpleHands[i].fingers.size() == 1) {
          
    }
     if (simpleHands[i].fingers.size() == 1) {
          
    }
}

But maybe this is not what you need. I´m not sure what you´re trying to do.

1 Like

Hello

It was just the speed of the leap detection who was too fast to make some different command with the fingers :slight_smile:
But it’s working now, thank you very much !!!

V