How do I force my RGB LED to be off when powering on Panda II?

I have a RGB LED in my project. When I power on my Panda II, the LED displays as a faint green and then displays as a much brighter blue. The blue color remains until my code changes the color to a cyan color. How do I keep the RGB LED powered off until my code changes the LED to cyan?

FYI, the RGB LED is bright blue before the FOR loop executes to flash the onboard LED.

Further, this behavior continues even if I remove the code that creates the PWM[] named rgb. Just having the RGB LED plugged into the breadboard is enough to have it display a faint green before becoming bright blue. This doesn’t appear to be related to my code.


    public class Program
    {
        static Thread thread;

        static PWM[] rgb = new PWM[]
                {
                    new PWM((PWM.Pin)FEZ_Pin.PWM.Di5),
                    new PWM((PWM.Pin)FEZ_Pin.PWM.Di6),
                    new PWM((PWM.Pin)FEZ_Pin.PWM.Di10)
                };

        public static void Main()
        {

            // Enable the Ethernet
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
            Dhcp.EnableDhcp(new byte[] { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 }, "FEZ Temp/Light");

            // Show we've started by blinking the LED
            bool ledState = false;
            OutputPort led = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);

            for (int i = 0; i < 20; i++)
            {
                ledState = !ledState;
                led.Write(ledState);
                Thread.Sleep(100);
            }


            // Begin sampling the temperature
            thread = new Thread(TempFromMaximIc);
            thread.Priority = ThreadPriority.Normal;
            thread.Start();


            //TempFromMaximIc();

        }

Try adding pull-down resistors

As Eric says, the only way to make sure you have an output set to be the explicit way you want it to be at system power-on is to use a pull-up or pull-down resistor. The choice of pull-up or pull-down will make the output set in the way you want (either on or off) based on what your output device (the LED in your case) wants. If you don’t do that, then the output is in a floating state and you can’t be sure whether it’s high or low, and therefore the output device may be on or off until your code starts and initialises it into the state you want.

This is a common design criteria where you need absolute control over power-on state; for example if you have a solenoid controlling a water in a garden watering system, you can’t have it open when the system is restarting, you need to have it explicitly closed unless opened and you’d set the output appropriately with a resistor to guarantee that.