Pages: [1]   Go Down
Author Topic: delay() before setup()?  (Read 512 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an LCD panel that boots up the same time as the Arduino that is connected to it. I want the Arduino to wait until the LCD is all powered up and it's flash screens are done before it runs it's own code.

I know I could test this but not in the position to do so at the moment.

Will delay() work in the code before the void setup() ? I assume it will, but like I said, can't test atm.

Are their better alternatives? I don't like using the delay() function because of how it works. But I think using it before the setup might be OK, and it's not something that will be repeated unless a reboot happens.

Is their a way to tell the Arduino to reboot programicaly?


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Will delay() work in the code before the void setup() ? I assume it will, but like I said, can't test atm.
No, it won't. The delay() function is executable code. All executable code must be in a function block.

There is no reason you couldn't put the delay() as the first thing in setup(), so that only the constructors and init() method are executed before you stop doing anything for a while.

Quote
Is their a way to tell the Arduino to reboot programicaly?
If you need to, there is something wrong with your code. Fix that problem FIRST.
Logged

0
Offline Offline
Sr. Member
****
Karma: 1
Posts: 415
MEGA_Stick_II is here
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is their a way to tell the Arduino to reboot programicaly?
If you need to, there is something wrong with your code. Fix that problem FIRST.

Don't need to no, just was wondering.

The issue is that the Arduino boots up first and starts reading and recording data. It updates the panel only when the data changes. So by the time the LCD is all powered up, it shows all 0's until the data changes and it gets updated. So I need the LCD to power up first so it don't miss the first update from the Arduino. If there was a way to tell the Arduino to reboot, the LCD could send a reboot when it's ready to receive data. I guess I could tell the Arduino to wait for a signal from the panel, but the delay() in the setup should work just as good and it's simple.

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I guess I could tell the Arduino to wait for a signal from the panel, but the delay() in the setup should work just as good and it's simple.
Depending on the LCD, and the library being used, the LCD may be readable - it may be able to tell you when it is ready.

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Quote
Will delay() work in the code before the void setup() ? I assume it will, but like I said, can't test atm.

as PaulS states put the delay as first command in your setup().
Code:
void setup()
{
  delay(10000UL);
  etc
}

Another option is to patch the Arduino main() function that can be found in main.cpp in your duino distribution

(this is 0.22 version, other versions differ slightly)
Code:
#include <WProgram.h>

int main(void)
{
init();
        delay(10000UL);  // <<<<<<<<<<<<<<<<< add this line
setup();
   
for (;;)
loop();
       
return 0;
}
problem is that you will get it in every executable... but that is no problem either as you can remove it again ... and again ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: