Newbie Question about using "void setup()"

Everything I have been reading about void setup() says its run one time at the start of the program. But I'm working on a code example that appears to continually use the code in void setup(). I have not found an example or explanation that shows/tells me how this works.

in the code example below, the boolean debounce function seems to be run on each loop. I'm not fully understanding how or why if the code in void setup() is only run once at the beginning of the program. The debounce function would need to be looked at in every loop. Why is the debounce function in void setup() and not part of the void loop()?

[quote

// Ch2-5 Jeremy Blum
// edits and tweeks by me..

const int LED=9;
const int BUTTON=2;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;

void setup()
{
  pinMode (LED, OUTPUT);
  pinMode (BUTTON, INPUT);
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(BUTTON);
  if (last != current)
  {
    delay(5);
    current = digitalRead(BUTTON);
    
  return current;
  }
}
void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledOn = !ledOn;
  }
  lastButton = currentButton;
  
  digitalWrite(LED, ledOn);
}

[/quote]

Why is the debounce function in void setup()

It is not. There are only two statements in the setup function. The function definition is surrounded by { and }

The debounce function is called from the loop function in this line:-

currentButton = debounce(lastButton);

The code:-

boolean debounce(boolean last)
{
  boolean current = digitalRead(BUTTON);
  if (last != current)
  {
    delay(5);
    current = digitalRead(BUTTON);
   
  return current;
  }
}

Is a new function your code has defined, it's name is debounce

click the MODIFY button in the upper right of the post window. Highlight all you code. click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button. click SAVE (at the bottom). When you post code on the forum, please make a habit of using the code tags "#" button.

FYI, Once the function is loaded on the first pass in void setup it resides in ram as available for calls.

raschemmel: FYI, Once the function is loaded on the first pass in void setup it resides in ram as available for calls.

No. On the arduino all code is in flash memory not RAM.

Sorry, that's what I meant.