We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Input Inactivity event
Page Index Toggle Pages: 1
Input Inactivity event (Read 813 times)
Input Inactivity event
Dec 5th, 2009, 8:06am
 
Hi there

Am trying to figure out how to implement inactivity as part of interaction.

Basically, after 3 seconds reset & display loop of visual static. Otherwise, if input detected within 3s keep on playing motion feature?

How would this be possible?

thanks

this code displays a main movie once button pressed & depressed plays static loop. I am aiming to keep movie playing if button continually pressed within 3s time, otherwise return to static. Not getting anywhere.


Code:

void draw(){
if (arduino.digitalRead(buttonPin) == 1){
image(theMovie, 0, 0);
}
else {
image(theWhite, 0, 0);
}
theMovie.loop();
}


Re: Input Inactivity event
Reply #1 - Dec 5th, 2009, 8:46am
 
When you detect activity, set a global variable to millis() value.
On each frame, check if millis() - lastActivityTime is above 3s. If so, display alternative stuff.
Re: Input Inactivity event
Reply #2 - Dec 5th, 2009, 9:33am
 
thanks for replying. I'm trying to implement what you're suggesting as:

the problem arises with the two counters counting the same. would it be possible to count individually - i.e on button push start counting?

Code:
void draw(){  
millis = second();
println(millis);
if (arduino.digitalRead(buttonPin) == 1){
lastact = second();
println("input" + lastact);
if(millis - lastact > 3){println("pocahontas");}


// aim is to keep playing for 3 seconds after button push
image(theMovie, 0, 0);
Re: Input Inactivity event
Reply #3 - Dec 5th, 2009, 9:47am
 
You are confusing the 2 functions millis() and second()
Code:

void draw(){  
   millis = millis();
   println(millis);
   if (arduino.digitalRead(buttonPin) == 1){
        lastact = millis();
        println("input" + lastact);
   }
   if(millis - lastact < 3000){println("pocahontas");
       // aim is to keep playing for 3 seconds after button push
       image(theMovie, 0, 0);
   }
   else {
       // do something else after 3 seconds
   }
}

I don't have an arduino to test it out but hopefully this will work.
Re: Input Inactivity event
Reply #4 - Dec 5th, 2009, 11:22am
 
thanks, this works a charm
Re: Input Inactivity event
Reply #5 - Dec 6th, 2009, 2:21am
 
The base was OK, but as Quark points out, it was lacking precision.
And for the record, millis - lastact is always negative... (and different from my millis() - lastAct! Wink)
Page Index Toggle Pages: 1