Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

Characteristic Locus
Inheritance object > PwmLed
Implements IPwmLed IDisposable
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 PwmLed : IPwmLed, IDisposable

Constructors

PwmLed(IPin, Voltage, CircuitTerminationType)

Initializes a new instance PwmLed class

Declaration
public PwmLed(IPin pin, Voltage forwardVoltage, CircuitTerminationType terminationType = CircuitTerminationType.CommonGround)

Parameters

Type Name Description
IPin pin

Pin

Voltage forwardVoltage

Forward voltage

CircuitTerminationType terminationType

Whether the other end of the LED is hooked to ground or High. Typically used for RGB Leds which can have either a common cathode, or common anode. But can also enable an LED to be reversed by inverting the PWM signal.

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

PwmLed(IPwmPort, Voltage, CircuitTerminationType)

Creates a new PwmLed on the specified PWM pin and limited to the appropriate voltage based on the passed forwardVoltage. Typical LED forward voltages can be found in the TypicalForwardVoltage class.

Declaration
public PwmLed(IPwmPort pwmPort, Voltage forwardVoltage, CircuitTerminationType terminationType = CircuitTerminationType.CommonGround)

Parameters

Type Name Description
IPwmPort pwmPort

Port to control

Voltage forwardVoltage

Forward voltage of led

CircuitTerminationType terminationType

Termination type of LED

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

Properties

Brightness

The brightness value assigned to the LED

Declaration
public float Brightness { get; protected set; }

Property Value

Type Description
float

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

ForwardVoltage

Gets the forward voltage value

Declaration
public Voltage ForwardVoltage { get; protected set; }

Property Value

Type Description
Voltage

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

IsDisposed

Is the object disposed

Declaration
public bool IsDisposed { get; }

Property Value

Type Description
bool

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

IsOn

Turns on LED with current color or turns it off

Declaration
public bool IsOn { get; set; }

Property Value

Type Description
bool

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

MAX_FORWARD_VOLTAGE

Maximum forward voltage (3.3 Volts)

Declaration
public Voltage MAX_FORWARD_VOLTAGE { get; }

Property Value

Type Description
Voltage

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

MIN_FORWARD_VOLTAGE

Minimum forward voltage (0 Volts)

Declaration
public Voltage MIN_FORWARD_VOLTAGE { get; }

Property Value

Type Description
Voltage

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

Port

Gets the PwmPort

Declaration
protected IPwmPort Port { get; set; }

Property Value

Type Description
IPwmPort

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

Dispose(bool)

Dispose of the object

Declaration
protected virtual void Dispose(bool disposing)

Parameters

Type Name Description
bool disposing

Is disposing

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

SetBrightness(float)

Sets the LED to a specific brightness.

Declaration
public void SetBrightness(float brightness)

Parameters

Type Name Description
float brightness

Valid values are from 0 to 1, inclusive

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

Start a Blink animation which sets the brightness of the LED alternating between a low and high brightness setting.

Declaration
public Task StartBlink(float highBrightness = 1, float lowBrightness = 0)

Parameters

Type Name Description
float highBrightness

The maximum brightness of the animation

float lowBrightness

The minimum brightness of the animation

Returns

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

Start the Blink animation which sets the brightness of the LED alternating between a low and high brightness setting, using the durations provided.

Declaration
public Task StartBlink(TimeSpan highBrightnessDuration, TimeSpan lowBrightnessDuration, float highBrightness = 1, float lowBrightness = 0)

Parameters

Type Name Description
TimeSpan highBrightnessDuration

The duration the LED stays in high brightness

TimeSpan lowBrightnessDuration

The duration the LED stays in low brightness

float highBrightness

The maximum brightness of the animation

float lowBrightness

The minimum brightness of the animation

Returns

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

StartPulse(float, float)

Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting.

Declaration
public Task StartPulse(float highBrightness = 1, float lowBrightness = 0.15)

Parameters

Type Name Description
float highBrightness

The maximum brightness of the animation

float lowBrightness

The minimum brightness of the animation

Returns

Type Description
Task

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

StartPulse(TimeSpan, float, float)

Start the Pulse animation which gradually alternates the brightness of the LED between a low and high brightness setting, using the durations provided.

Declaration
public Task StartPulse(TimeSpan pulseDuration, float highBrightness = 1, float lowBrightness = 0.15)

Parameters

Type Name Description
TimeSpan pulseDuration

The pulse animation duration

float highBrightness

The maximum brightness of the animation

float lowBrightness

The minimum brightness of the animation

Returns

Type Description
Task

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

StopAnimation()

Stops any running animations.

Declaration
public Task StopAnimation()

Returns

Type Description
Task

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

ValidateBrightness(float, float)

Validates LED brightness to ensure they're within the range 0 (off) - 1 (full brightness)

Declaration
protected void ValidateBrightness(float highBrightness, float lowBrightness)

Parameters

Type Name Description
float highBrightness

The maximum brightness of the animation

float lowBrightness

The minimum brightness of the animation

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"

ValidateForwardVoltages(Voltage)

Validates forward voltages to ensure they're within the range MIN_FORWARD_VOLTAGE to MAX_FORWARD_VOLTAGE

Declaration
protected void ValidateForwardVoltages(Voltage forwardVoltage)

Parameters

Type Name Description
Voltage forwardVoltage

The forward voltage for the LED

Remarks

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

*PwmLed represents an LED whose voltage (and brightness) is controlled by the duty-cycle of a PWM signal. It can be used both with Leds that have been current limited with in-series resistors, or Leds without resistors.

Controlling an LED via a PWM signal is more power efficient than using a current-limiting resistor. It also provides more control, allowing multiple grades of brightness.

To use PwmLed without a resistor, pass in the forward voltage (voltage drop) of the LED to the forwardVoltage constructor parameter, and the class will limit its output to the maximum forward voltage rating of the LED.

To use with an LED that has a resistor in series, pass 0.0 or TypicalForwardVoltage.ResistorLimited for the forwardVoltage parameter.

Code Example

PwmLedBarGraph pwmLedBarGraph;

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

    // Using an array of Pins that support PWM (D02 - D13)
    IPin[] pins =
    {
         Device.Pins.D11,
         Device.Pins.D10,
         Device.Pins.D09,
         Device.Pins.D08,
         Device.Pins.D07,
         Device.Pins.D06,
         Device.Pins.D05,
         Device.Pins.D04,
         Device.Pins.D03,
         Device.Pins.D02
    };

    pwmLedBarGraph = new PwmLedBarGraph(pins, new Voltage(2.2));

    return Task.CompletedTask;
}

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

    float percentage = 0;

    while (true)
    {
        Resolver.Log.Info("Turning them on and off for 200ms using SetLed...");
        for (int i = 0; i < pwmLedBarGraph.Count; i++)
        {
            await pwmLedBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await pwmLedBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them off using Percentage...");
        while (percentage > 0)
        {
            percentage -= 0.01f;
            await pwmLedBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 500ms on/off...");
        await pwmLedBarGraph.StartBlink();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar blinking with high and low brightness for 5 seconds...");
        await pwmLedBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200), 0.75f, 0.25f);
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        Resolver.Log.Info("Bar pulsing for 5 seconds...");
        await pwmLedBarGraph.StartPulse();
        await Task.Delay(5000);
        await pwmLedBarGraph.StopAnimation();

        await Task.Delay(1000);

        await pwmLedBarGraph.SetBrightness(0);

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Leds.PwmLed/PwmLed_Fritzing.svg"