You could (and I occasionally do) write your entire program in the setup()
function. Setup()
and loop()
are constructs provided for your convenience, but they aren't necessary. In C/C++ compiled programs, it conventional for the C run-time code to call main()
, and for main()
to be written by the programmer.
It is conventional within the Arduino IDE world to bury the complicated stuff to let new user get productive quickly with a gentle learning curve.
That includes a pre-written main()
that provides the calls to setup()
and loop()
for you.
The following main()
function is typical of a number of pre-written Arduino main()
functions, but you don't have to use the pre-written one; you can supply your own. It will need to call init()
, and Arduino library function that prepares the hardware and software environment into a known state; after that you're good to go.
/*
* main.cpp
*
* Created on: Dec 13, 2011
* Author: jrobert
*/
#include "WProgram.h"
int main(void){
init();
setup();
for(;;)
loop();
}
extern "C" void __cxa_pure_virtual() {
while (1)
;
}