Technically there's no reason you can't call setup() - but there's probably not any good reason to. If your setup does things that should only be done once at program start (like Serial.begin()), then it would be a really bad idea.

Putting a "return" in the loop() function won't do anything. The actual code that's generated by the IDE calls the loop() function in an infinite loop.

/* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We use pin 13 because, * depending on your Arduino board, it has either a built-in LED * or a built-in resistor so that you need only an LED. * * http://www.arduino.cc/en/Tutorial/Blink */

void loop() // run over and over again{ digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second}

int main(void){ init();

setup();

for (;;) loop();

return 0;}

The "real" program that runs is the main() function. Note that it calls some Arduino core initialization that's not visible to the program (init()), calls your set() function, and then loops forever calling loop().

So there's no way to make the program "end". Besides, what would be the point of having a program end on a micorcontroller? If that happened the chip would just go "dead" until it got reset.

If you really want this behavior you can simply comment out the for loop in the main program template so it only calls loop() once (or change it to do something more radical like not call loop() at all):

There's no way to terminate the infinite loop that keeps on calling "loop ()", over and over again. But if you want the Arduino to stop what it's doing and "hang", you can code your own infinite loop, doing nothing:

Once the flow of control enters that loop, it'll never exit. The Arduino continues to run, though, until reset. This means that it will continue to draw power from your power supply, which is bad if it's a battery! In that case, use the "sleep" technique mentioned above.

It depends on what you mean by "shutting down the board". Do you want to just stop the actions of your sketch? Or do you want to stop things like PWM outputs and servo pulses, too? Or are you trying to switch off the board to reduce power consumption?

Ran across this last night. give it a look. It is uses the sleep function, and there is some source code to look at too. http://interface.khm.de/index.php/labor/experimente/sleep_watchdog_battery/He breaks down the Arduino to the core needs. Minimalism at it's best.