Pages: [1]   Go Down
Author Topic: Stop - before Loop?  (Read 770 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is it possible to stop the loop from runnning.

Im using an ethernet shield, and if it fails to obtain a local LAN Ip, I want to stop the loop from running.. can I do this?

so In void setup I have this line..
Code:
if (Ethernet.begin(mac) == 0) {

   { Serial.println("Failed to configure Ethernet using DHCP");
    lcd.setCursor(0,0);
lcd.print("LAN FAILURE !");
delay(1000);}
/// I want this to stop the loop from running from here . HOW?

do I create a else comment in loop and do nothing if (Ethernet.begin(mac) == 0)

any help would be appreciated...

David
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wouldn't it be more stylish to loop retrying the DHCP connection than simply to stop?

Anyway, you can just write a forever loop: "while (1) {;}" to stop execution.

-br
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wouldn't it be more stylish to loop retrying the DHCP connection than simply to stop?

Anyway, you can just write a forever loop: "while (1) {;}" to stop execution.

-br

Yes it would, but as it is even if my LAN is down, the loop begins..
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4817
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could check the LAN in setup().

Either way, while (1); ( save yer fingers, you don't need the { } ) will hang the code instantly. It's budget error-handling.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Shannon Member
****
Karma: 217
Posts: 12583
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can always set a flag if initialization fails and test that in loop...  Perhaps you want something else to happen in that case
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could check the LAN in setup().

Either way, while (1); ( save yer fingers, you don't need the { } ) will hang the code instantly. It's budget error-handling.




That was easy.. many thanks !-)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (Ethernet.begin(mac) == 0) {

   { Serial.println("Failed to configure Ethernet using DHCP");
    lcd.setCursor(0,0);
lcd.print("LAN FAILURE !");
delay(1000);}
/// I want this to stop the loop from running from here . HOW?


Use exit();

And indent better.

 
Code:
 if (Ethernet.begin (mac) == 0)
    {
    Serial.println ("Failed to configure Ethernet using DHCP");
    lcd.setCursor (0,0);
    lcd.print ("LAN FAILURE !");
    delay (1000);
    exit (1);     // give up
    }

Don't be shy to hit the space bar. You don't get charged extra for spaces.
Logged


Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4817
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh yeah.. exit(). I haven't used it with Arduino because for years it means exit to O/S to me!

Please for review, does exit stop any clocks and cut power use?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh yeah.. exit(). I haven't used it with Arduino because for years it means exit to O/S to me!

Please for review, does exit stop any clocks and cut power use?

I have to resist making humorous suggestions here ...

No, it turns interrupts off and goes into an infinite loop. That's all.
Logged


Pages: [1]   Go Up
Jump to: