i have a beginner question! i understand that setup() runs when the board is initialized and that loop() runs once per cycle. here's an example to illustrate my question:
let's say i'm building a time machine (obviously this is top secret). when i start up the machine, i want to enter the current date, then i want to set the day, month and year of my destination. once this is set, i want to push the "go" button to travel through time.
of course i can do all this in the loop() function, checking my pins to set the date and checking when "go" is pushed. but i don't want anyone to be able to mess with the dates while the time_travel() function is being run! that would be dangerous. also, it seems a bit unnecessary for the loop() to continuously check the date and go controls once they are no longer needed. so, should i use the setup() function for this?
an example of setup() being used to gather initialization data is the analog calibration sketch that comes with the arduino software:
void setup() {
while (millis() < 5000) {
... gather data for calibration
}
}
but the time machine example would theoretically wait an undefined amount of time for you get ready for the trip before entering your dates and pressing "go". something like this perhaps:
void setup() {
for(int i=0; goButton == HIGH; i++) {
... read date inputs
... read goButton
}
}
so my question is: should i be doing this in the setup() function? or is there a way to do it all within the loop() function? what is best practice and why?