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.
Page Index Toggle Pages: 1
delay in setup (Read 933 times)
delay in setup
Oct 19th, 2009, 8:05am
 
Hi all,

how can i do an delay in the setup()? it seems to not be working there:

Code:
void setup() {
size(256,256);

println("hello");
delay(10000);
println("hello again");
}


void draw() {
}


Re: delay in setup
Reply #1 - Oct 19th, 2009, 8:15am
 
I think perhaps the response to that can only be: why do you need a delay in setup?  Given that the intention is to initialise your sketch and if necessary assign starting values to variables (so if you want to 'reset' your sketch you can simply call setup() again) it doesn't seem to make a lot of sense to want to use delay there.  Perhaps it would help to know what you're hoping to achieve with this delay...  I suspect the answer is that it should be placed in draw, if used at all.
Re: delay in setup
Reply #2 - Oct 19th, 2009, 9:02am
 
It is by design, delay() works only if frameCount > 0
If you really need to do a delay in setup(), use the code in delay():
Code:
try {
Thread.sleep(napTime);
} catch (InterruptedException e) { }
Re: delay in setup
Reply #3 - Oct 19th, 2009, 9:18am
 
thx for answer. i wanna use the delay in setup, is i'm initialising some devices there. after initialising i want to wait a couple of millis in order to not overload the arduino. if i don't, i sometims only get crap from the board. doesn't that make sense?

this is handy to do in setup as i only need to do it once.
Re: delay in setup
Reply #4 - Oct 19th, 2009, 10:03am
 
I don't know Arduino; maybe there's a proper solution...But I'd say, if you can describe what makes the data junk, you could devise a test for the information returned by the device.  That'd be a way to be absolutely sure.  For example, there are functions like Float.parseFloat( any data ), which will try to return a float and throw an exception if it's not possible -- so it has to be in a try{} catch{} statement:

  try{
     numData = Float.parseFloat( testData );
     numFound = true;
   }
   catch (Exception e){
     println(testData + " is not a number!");
     numFound = false;
   }
Re: delay in setup
Reply #5 - Oct 19th, 2009, 2:50pm
 
I'd agree: you want to be checking that what you get through from the Arduino is what you expect before doing anything with it.  That's going to make your application more robust.

However if I've understood you correctly in some situations the initial connection causes some kind of feedback that breaks the Arduino programme meaning it only sends through 'junk'  Does you Arduino programme check it is getting what it expects also  Perhaps this is a question for the Electronics, Serial Library board...

If I were you I'd rather find a robust solution to the problem than try and work around it with delay (or equivalent) in setup.
Re: delay in setup
Reply #6 - Oct 20th, 2009, 2:33am
 
you're right, delay is just a quick and dirty sollution. working with the catch{} statement is a much cleaner thing. im gonna do it that way. thx
Page Index Toggle Pages: 1