Arduino sketches usually feature a setup
and loop
function. Are these functions only provided for convenience or do they actually have special purposes? (e.g.: are some operations disallowed or allowed in setup and loop)
Are these two pieces of code equivalent:
Classic
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
Without loop
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
while(true) {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
}
void loop() {
}
Is it possible to write code without either setup or loop, providing, for example, a main
method or other entry point?