Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Characteristic Locus
Inheritance object > RgbLed
Implements IRgbLed
Inherited Members object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.Leds
Assembly Meadow.Foundation.dll

Syntax

public class RgbLed : IRgbLed

Constructors

RgbLed(IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, CommonType)

Create instance of RgbLed

Declaration
public RgbLed(IDigitalOutputPort redPort, IDigitalOutputPort greenPort, IDigitalOutputPort bluePort, CommonType commonType = CommonType.CommonCathode)

Parameters

Type Name Description
IDigitalOutputPort redPort

Red Port

IDigitalOutputPort greenPort

Green Port

IDigitalOutputPort bluePort

Blue Port

CommonType commonType

Is Common Cathode

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

RgbLed(IPin, IPin, IPin, CommonType)

Create instance of RgbLed

Declaration
public RgbLed(IPin redPin, IPin greenPin, IPin bluePin, CommonType commonType = CommonType.CommonCathode)

Parameters

Type Name Description
IPin redPin

Red Pin

IPin greenPin

Green Pin

IPin bluePin

Blue Pin

CommonType commonType

Is Common Cathode

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Properties

BluePort

The blue LED port

Declaration
protected IDigitalOutputPort BluePort { get; set; }

Property Value

Type Description
IDigitalOutputPort

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Color

The current LED color

Declaration
public RgbLedColors Color { get; protected set; }

Property Value

Type Description
RgbLedColors

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Common

The common type (common anode or common cathode)

Declaration
public CommonType Common { get; protected set; }

Property Value

Type Description
CommonType

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

GreenPort

The green LED port

Declaration
protected IDigitalOutputPort GreenPort { get; set; }

Property Value

Type Description
IDigitalOutputPort

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

IsOn

Turns on LED with current color or turns it off

Declaration
public bool IsOn { get; set; }

Property Value

Type Description
bool

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

RedPort

The red LED port

Declaration
protected IDigitalOutputPort RedPort { get; set; }

Property Value

Type Description
IDigitalOutputPort

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Methods

SetColor(RgbLedColors)

Sets the current color of the LED.

Declaration
public void SetColor(RgbLedColors color)

Parameters

Type Name Description
RgbLedColors color

The color value

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Start the Blink animation which sets turns the LED on and off on an interval of 1 second (500ms on, 500ms off)

Declaration
public Task StartBlink()

Returns

Type Description
Task
RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Start the Blink animation which sets turns the LED on and off on an interval of 1 second (500ms on, 500ms off)

Declaration
public Task StartBlink(RgbLedColors color)

Parameters

Type Name Description
RgbLedColors color

The LED color

Returns

Type Description
Task
RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Start the Blink animation which sets turns the LED on and off with the specified durations and color

Declaration
public Task StartBlink(RgbLedColors color, TimeSpan onDuration, TimeSpan offDuration)

Parameters

Type Name Description
RgbLedColors color

The LED color

TimeSpan onDuration

The duration the LED stays on

TimeSpan offDuration

The duration the LED stays off

Returns

Type Description
Task
RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Start the Blink animation which sets turns the LED on and off with the specified durations and current color

Declaration
public Task StartBlink(TimeSpan onDuration, TimeSpan offDuration)

Parameters

Type Name Description
TimeSpan onDuration

The duration the LED stays on

TimeSpan offDuration

The duration the LED stays off

Returns

Type Description
Task
RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

StopAnimation()

Stops the current LED animation

Declaration
public Task StopAnimation()

Returns

Type Description
Task

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

UpdateLed(bool)

Turns on LED with current color or LED off

Declaration
protected void UpdateLed(bool isOn)

Parameters

Type Name Description
bool isOn

True for on, False for off

Remarks

RgbLed
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

RgbLed represents an RGB LED whose color is controlled by three digital output ports. These diodes consist of four legs - one for each of the colors mentioned and one for a common cathode (ground) or common anode (vcc), which is also the longest one.

Common Cathode/Common Anode RGB LEDs

To connect these deds to Meadow, it is recommended to use an external resistor of ~270 to 1K ohms to prevent too much current from flowing through the led and causing damage.

Circuit of a common anode RGB LED

Common Anode RGB LEDs

Circuit of a common cathode RGB LED

Common Cathode RGB LEDs

Code Example

protected List<RgbLed> rgbLeds;

public override Task Initialize()
{
    Resolver.Log.Info("Initializing...");

    rgbLeds = new List<RgbLed>
    {
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D02),
            Device.CreateDigitalOutputPort(Device.Pins.D03),
            Device.CreateDigitalOutputPort(Device.Pins.D04)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D05),
            Device.CreateDigitalOutputPort(Device.Pins.D06),
            Device.CreateDigitalOutputPort(Device.Pins.D07)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D08),
            Device.CreateDigitalOutputPort(Device.Pins.D09),
            Device.CreateDigitalOutputPort(Device.Pins.D10)),
        new RgbLed(
            Device.CreateDigitalOutputPort(Device.Pins.D11),
            Device.CreateDigitalOutputPort(Device.Pins.D12),
            Device.CreateDigitalOutputPort(Device.Pins.D13))
    };

    return Task.CompletedTask;
}

public override async Task Run()
{
    Resolver.Log.Info("TestRgbLeds...");

    while (true)
    {
        Resolver.Log.Info("Going through each color on each RGB LED...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                rgbLed.SetColor((RgbLedColors)i);
                await Task.Delay(500);
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 500ms / off 500ms)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i);
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking through each color on each RGB LED (on 1s / off 1s)...");
        foreach (var rgbLed in rgbLeds)
        {
            for (int i = 0; i < (int)RgbLedColors.count; i++)
            {
                await rgbLed.StartBlink((RgbLedColors)i, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
                await Task.Delay(3000);
                await rgbLed.StopAnimation();
                rgbLed.IsOn = false;
            }
        }

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub