Proceedures in Setup

Spending time getting up to speed programming Arduino. I promise questions will slow down shortly...

I'm working with a piece of demo code for learning purposes and I've learned that all statements in setup() run at initialization and then flow goes to the loop() section of code.

However: I've got a couple proceedures in setup() and wanted to know if, after the in-line statments are executed, will the proceedures be executed before execution drops to loop(), or will the proceedures only be executed when called from the loop section of code? I assume only when called.

And what are the considerations regarding placing proceedures loop() or setup() section of the program?

Is it just about from where the proceedure will be called?

What if it will be called from both setup() and loop()?

Here's some of the code-

void setup() { Serial.begin(9600);//For access to serial monitor channel pinMode(Out0,OUTPUT); Serial.print("Enter s or f on serial terminal "); Serial.println("to make wink fast or slow"); //Two lines used just for readability on //a web page that explains this program. }

void fastwink() //Do one quick on-off... this is called many times as //the function "loop" executes repeatedly, thus the //Arduino appears to have a "wink quickly" function, //even though the quick winking is a combination of //two ingredients { digitalWrite(Out0,HIGH); delay(80); digitalWrite(Out0,LOW); delay(80); }

void slowwink() //Similar to fastwink. See rem there. { digitalWrite(Out0,HIGH); delay(900); digitalWrite(Out0,LOW); delay(900); }

void loop() { int incomingByte=0;//create and initialize a local variable

//The "then" part of the following will --snip--

Your program looks like this:

main () {
  init (); // you never see this
  setup ();  // this is what you write - it gets executed just once
  while (1) {
    loop (); // and you write this bit - it executes forever.
  }
}

When posting code, please use the # button on the editor's toolbar to enclose your sketch.

I'm not sure I understand the question, but perhaps: functions/procedures in arduino sketches are executed only when called from code, which has nothing to do with the order in which the source code appears in your editor window. So you can define your procedures (fastwink(), slowwink()) in the source code before you define setup() and loop(), and they will only be executed when called from inside of loop().

PS: I frequently put code similar to "fastwink()" in setup() so that I can see when the sketch actually starts running.

Thanks Westfw. That helps.

Looking closer it is becoming apparent that Setup() and Loop() are nothing more than proceedures themselves. And where proceedures are located is unimportant.

Now it look slike I need to spend some time understanding variable scope....