What is the earliest moment after startup to light a LED, and how do I get there?

I am trying to light some LEDs as soon as possible after the Particle Core has been powered on (function test).

However, sometimes it takes more than 10 seconds until the first instruction in setup() is processed. I assume this is because the Core tries to connect to the network first. How can I do something before that? Is setup() the right place?

Thank you!

SYSTEM_MODE(SEMI_AUTOMATIC);

void setup() {
    pinMode(D7, OUTPUT);
    digitalWrite(D7,HIGH);
    Spark.connect();
}

void loop() {
}

:smile:

1 Like

@Sleziak nailed it.

For more info on SYSTEM_MODE(SEMI_AUTOMATIC), check out https://docs.particle.io/reference/firmware/photon/#system-modes.

In the 0.4.4 firmware, we have the STARTUP() macro that you can use for early execution, so you don’t have to change system mode:

void init_led()
{
    pinMode(D7, OUTPUT);
    digitalWrite(D7,HIGH);
}

STARTUP(init_led());
```

If you're using a Core, the 0.4.5 firmware will be released tomorrow.
2 Likes

Wow, that is so great. Thank you, all!