Answer the question
In order to leave comments, you need to log in
Why are functions created after they are used in the code examples in the book?
I'm learning how to write sketches for Arduino from the book "Programming the Arduino. Basics of working with sketches" by Simon Monk. In the book, in code examples, functions are first called and only then written.
For example like this:
void loop()
{
flash(20, delayPeriod);
delay(3000);
}
void flash(int numFlashes, int d)
{
for (int i = 0; i < numFlashes; i ++)
{
digitalWrite(ledPin, HIGH);
delay(d);
digitalWrite(ledPin, LOW);
delay(d);
}
}
void flash(int numFlashes, int d)
{
for (int i = 0; i < numFlashes; i ++)
{
digitalWrite(ledPin, HIGH);
delay(d);
digitalWrite(ledPin, LOW);
delay(d);
}
}
void loop()
{
flash(20, delayPeriod);
delay(3000);
}
Answer the question
In order to leave comments, you need to log in
Previous versions of the IDE allowed this (when compiling, they automatically placed the functions as they should).
More recent versions of the IDE don't take it easy anymore and you have to strictly follow C++ standards.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question