setup vs loop


i have beginner question!  i understand setup() runs when board initialized , loop() runs once per cycle.  here's example illustrate question:

let's i'm building time machine (obviously top secret).  when start machine, want enter current date, want set day, month , year of destination.  once set, want push "go" button travel through time.

of course can in loop() function, checking pins set date , checking when "go" pushed.  but don't want able mess dates while time_travel() function being run!  that dangerous.  also, seems bit unnecessary loop() continuously check date , go controls once no longer needed.  so, should use setup() function this?

an example of setup() being used gather initialization data analog calibration sketch comes arduino software:
code: [select]
void setup() {
  while (millis() < 5000) {
     ... gather data calibration
  }
}

but time machine example theoretically wait undefined amount of time ready trip before entering dates , pressing "go".  something perhaps:
code: [select]
void setup() {
  for(int i=0; gobutton == high; i++) {
     ... read date inputs
     ... read gobutton
  }
}


so question is: should doing in setup() function?  or there way within loop() function?  what best practice , why?

if it's once-only setup, there's no reason not in "setup ()".

(make sure time-travellers don't have access reset button)


ps won't tell soul top secret project. promise.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > setup vs loop


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums