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 & HelpIntegration › Writing every x seconds
Page Index Toggle Pages: 1
Writing every x seconds (Read 1116 times)
Writing every x seconds
Nov 30th, 2009, 6:19am
 
Hey everyone,

I am currently writing some code and I need to save some values that I am getting from Arduino to a .txt file, but I want processing to write them every x seconds, because now the frameRate is 10 and it's writing very very fast, and in the .txt file I get lots same numbers.

The thing is that in my sketch I am also drawing some nice graphs so I cannot change the frameRate in order to write those values to the txt file slower.. is there any way to do this without modifying frameRate()?

Thanks in advance!
Re: Writing every x seconds
Reply #1 - Nov 30th, 2009, 8:09am
 
if you dont need accurate seconds and just want to slowdown the saving you can simply use

if(frameCount%x ==0) save

where x is the number of frames to skip. and save is whatever you want to do
Re: Writing every x seconds
Reply #2 - Nov 30th, 2009, 8:13am
 
Classical way:
Code:
if (millis() - lastWritingTime > DELAY_BETWEEN_WRITES)
{
 doYourWriting();
 lastWritingTime = millis();
}

Of course, declare lastWritingTime variable and DELAY_BETWEEN_WRITES constant as global variables.

[EDIT] Cedric was faster...
His method has the advantage to be simple (no global variable to set).
My method has the advantage to still save at same rate even if you change the frameRate. Of course, you can change the frameRate and the x variable at the same time...
Page Index Toggle Pages: 1