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 & HelpPrograms › Running some code just one time insde void draw
Page Index Toggle Pages: 1
Running some code just one time insde void draw (Read 988 times)
Running some code just one time insde void draw
Aug 13th, 2009, 6:29pm
 
Hello
I'm working on a program that communicates with a pic mcu via rs232. Inside this program i have an array that i need to read and store data retrieved from the mcu, but i don't need to do this on every frame so i think the better way to do this is just running through this piece of code just one frame once a time based conditional is fulfilled.
How will be the best way to acomplish this?

Thanks
Re: Running some code just one time insde void draw
Reply #1 - Aug 13th, 2009, 7:48pm
 
There are two ways to achieve it.

First one: assuming your sketch's frameRate is set to 60, it will then run your array once every second.

Code:
int runonce = 0;
if(runonce <= 60){
 runonce = runonce+1;
}
else{
// Call your array here
runonce = 0;
}


Second one: make use of boolean.

Code:
if(ConditionReached){ 
// your array here
}
Re: Running some code just one time insde void draw
Reply #2 - Aug 14th, 2009, 6:13am
 
jaylfk wrote on Aug 13th, 2009, 7:48pm:
Second one: make use of boolean.

Code:
if(ConditionReached){ 
// your array here
}


One slight modification to avoid problems:

Code:
if(ConditionReached){ 
// your array here
ConditionReached=false;
}

Re: Running some code just one time insde void draw
Reply #3 - Aug 14th, 2009, 7:23pm
 
Thanks for the answers. I'm working on the code right now and it seems to work just fine.

Thanks again
Page Index Toggle Pages: 1