Thursday, September 22, 2016

47: Did You Know?

—That your Arduino sketch can re-execute the setup function:

void setup() {
  . . .
  Serial.begin(9600);
  . . .
}

void loop() {
  // Some code
  . . .

}

So, if there is no serial connection when the Arduino powers up then the code will proceed to the loop. However, say you later connect to it with Coolterm (or equilalent command) then the setup will be executed again (for Serial.begin). I think it causes a hardware RESET.

Note that while a Particle Photon is Arduino-like, setup does not get re-executed in the above circumstance.

Probably doesn't matter, but it might.

No comments:

Post a Comment