Here's the 'bare minimum' Arduino sketch. This can be loaded into the Arduino IDE by choosing File > Examples > 01. Basics > Bare Minimum
.
void setup() {
// put your setup code here, to run once
}
void loop() {
// put your main code here, to run repeatedly
}
Code in the setup()
function will be run once when the program starts. This is useful to set up I/O pins, initialize variables, etc.
Code in the loop()
function will be run repeatedly until the Arduino is switched off or a new program is uploaded. Effectively, the code above looks like this inside the Arduino runtime library:
setup();
while(1) {
loop();
}
Unlike programs running on your computer, Arduino code can never quit. This is because the microcontroller only has one program loaded into it. If this program quit there would be nothing to tell the microcontroller what to do.