Can't use digitalWrite() in setup() to turn on external LEDs?

I'm building an annunicator panel using a Mega 2560, with some external 12v LEDs I'm switching with external transistors.

The circuitry all works fine is verified correct.

Switching LEDs on and off works fine in the main loop, but does not work in the setup() function.

I use exactly the same code. For testing I have boiled it down to simply setting pinMode to OUTPUT and digitalWrite(pin, HIGH)

I am using the explicit pin number for testing, not a variable. It is as simple as it gets.

The external LEDs do not illuminate when the code is in setup() but it works fine in the main loop.

Is this an Arduino limitation?

Oddly enough if I change the pin to 13, the onboard LED does illuminate as expected in the setup() function.

Again, this is NOT related to the circuitry, all that works fine and the exact same code (copy and paste) works in main loop.

I'm stumped.

Post your code, at least all the setup.

flightlead404:
I'm stumped.

So are we.

Something in the code is wrong. Please post it.

Switching LEDs on and off works fine in the main loop, but does not work in the setup() function.

No you are wrong, you are doing something wrong.

Is this an Arduino limitation?

No, there is nothing special about the setup function.

Oddly enough if I change the pin to 13, the onboard LED does illuminate as expected in the setup() function

That suggests to me you are not setting the pin to be an output as pin 13 can be an output by default on some boot loaders.

Or at least not using pinMode before calling digitalWrite.

it might work with INPUT, if the transistor is a MOSFET.

won't work with BJT.

CrossRoads:
Or at least not using pinMode before calling digitalWrite.

Not using pinMode in addition to calling digitalWrite. The order is largely unimportant.