Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Characteristic Locus
Inheritance object > LedBarGraph
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 LedBarGraph

Constructors

LedBarGraph(IDigitalOutputPort[])

Create an LedBarGraph instance from an array of IDigitalOutputPort

Declaration
public LedBarGraph(IDigitalOutputPort[] ports)

Parameters

Type Name Description
IDigitalOutputPort[] ports

The Digital Output Ports

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

LedBarGraph(IPin[])

Create an LedBarGraph instance from an array of IPins

Declaration
public LedBarGraph(IPin[] pins)

Parameters

Type Name Description
IPin[] pins

The Digital Output Pins

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Fields

leds

Array to hold LED objects for bar

Declaration
protected Led[] leds

Field Value

Type Description
Led[]

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Properties

Count

The number of the LEDs in the bar graph

Declaration
public int Count { get; }

Property Value

Type Description
int

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Percentage

A value between 0 and 1 that controls the number of LEDs that are activated

Declaration
public float Percentage { get; protected set; }

Property Value

Type Description
float

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Methods

GetTopLedForPercentage()

Returns the index of the last LED turned on

Declaration
public int GetTopLedForPercentage()

Returns

Type Description
int

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

SetLed(int, bool)

Set the LED state

Declaration
public Task SetLed(int index, bool isOn)

Parameters

Type Name Description
int index

Index of the LED

bool isOn

True for on, False for off

Returns

Type Description
Task

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

SetPercentage(float)

Set the percentage of LEDs that are on starting from index 0

Declaration
public Task SetPercentage(float percentage)

Parameters

Type Name Description
float percentage

Percentage (Range from 0 - 1)

Returns

Type Description
Task

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Blink animation that turns the LED bar graph on (500ms) and off (500ms)

Declaration
public Task StartBlink()

Returns

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Starts a blink animation on an individual LED on (500ms) and off (500ms)

Declaration
public Task StartBlink(int index)

Parameters

Type Name Description
int index

Index of the LED

Returns

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Starts a blink animation on an individual LED

Declaration
public Task StartBlink(int index, TimeSpan onDuration, TimeSpan offDuration)

Parameters

Type Name Description
int index

Index of the LED

TimeSpan onDuration

The duration the LED stays on

TimeSpan offDuration

The duration the LED stays off

Returns

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

Blink animation that turns the LED bar graph on and off based on the OnDuration and offDuration values

Declaration
public Task StartBlink(TimeSpan onDuration, TimeSpan offDuration)

Parameters

Type Name Description
TimeSpan onDuration

The duration the LED bar graph stays on

TimeSpan offDuration

The duration the LED bar graph stays off

Returns

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

StopAnimation()

Stops the LED bar graph when its blinking

Declaration
public Task StopAnimation()

Returns

Type Description
Task

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7

StopAnimation(int)

Stops the blinking animation on an individual LED

Declaration
public Task StopAnimation(int index)

Parameters

Type Name Description
int index

Returns

Type Description
Task

Remarks

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

An LED Bar Graph is packaged array of LEDs commonly used to indicate level or progress and commonly include 8 or 10 leds.

The LedBarGraph class allows you to control an led bar graph using GPIO.

LED bar graphs

Use the SetLed method to turn on or off LEDs individually, or assign a value on the Percentage property to represent it visually on the graph bar, like a battery indicator, temperature, humidity, etc.

Code Example

LedBarGraph ledBarGraph;

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

    // Using an array of Pins 
    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
    };

    ledBarGraph = new LedBarGraph(pins);

    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 < ledBarGraph.Count; i++)
        {
            await ledBarGraph.SetLed(i, true);
            await Task.Delay(100);
            await ledBarGraph.SetLed(i, false);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Turning them on using Percentage...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.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.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await Task.Delay(100);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Charging animation...");
        while (percentage < 1)
        {
            percentage += 0.10f;
            await ledBarGraph.SetPercentage(Math.Min(1.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

        Resolver.Log.Info("Discharging animation...");
        while (percentage > 0)
        {
            percentage -= 0.10f;
            await ledBarGraph.SetPercentage(Math.Max(0.0f, percentage));
            await ledBarGraph.StartBlink(ledBarGraph.GetTopLedForPercentage());
            await Task.Delay(2000);
        }

        await Task.Delay(1000);

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

        await Task.Delay(1000);

        Resolver.Log.Info("Blinking for 5 seconds at 200ms on/off...");
        await ledBarGraph.StartBlink(TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(200));
        await Task.Delay(5000);
        await ledBarGraph.StopAnimation();

        await Task.Delay(1000);
    }
}

Sample project(s) available on GitHub

Wiring Example

Circuit layout sample showing an LED BAR graph connected to a Meadow F7