Characteristic Locus
Inheritance System.Object > LedBarGraph
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Leds
Assembly Meadow.Foundation.dll

Syntax

public class LedBarGraph

Remarks

An LED Bar Graph is basically an LED array. Using an LED bar it’s as easy as connecting 10 individual LEDs with 10 output pins. Generally its used as a Battery level Indicator, Audio equipments, and Industrial Control panels. There are many other applications of LED bar graphs.

LED bars come in various sizes and single or multicolored. Using LedBarGraph, when creating an object, all it needs is to pass in an array of IDigitalPin.

Use 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.

Examples

The following example shows how to use the property Percentage to slowly fill and empty a 10 LED battery level graph:

using Meadow;
using Meadow.Devices;
using Meadow.Foundation.LEDs;
using Meadow.Hardware;
using System.Threading;

namespace SegmentedLedBar_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

    public class App : AppBase<F7Micro, App>
    {
        DigitalOutputPort _blueLED;
        LedBarGraph _ledBarGraph;

        public App ()
        {
            _blueLED = new DigitalOutputPort(Device.Pins.OnboardLEDBlue, true);

            var pins = new IDigitalPin[10];
            pins[0] = Device.Pins.D06;
            pins[1] = Device.Pins.D07;
            pins[2] = Device.Pins.D08;
            pins[3] = Device.Pins.D09;
            pins[4] = Device.Pins.D10;
            pins[5] = Device.Pins.D11;
            pins[6] = Device.Pins.D12;
            pins[7] = Device.Pins.D13;
            pins[8] = Device.Pins.D14;
            pins[9] = Device.Pins.D15;

            _ledBarGraph = new LedBarGraph(pins);

            Run();
        }

        void Run()
        {
            while (true)
            {
                float percentage = 0;

                while (percentage < 1)
                {
                    _ledBarGraph.Percentage = percentage;
                    percentage += 0.1f;
                    Thread.Sleep(200);                    
                }

                percentage = 1.0f;

                while (percentage > 0)
                {
                    _ledBarGraph.Percentage = percentage;
                    percentage -= 0.1f;
                    Thread.Sleep(200);                    
                }
            }
        }
    }
}
Example Circuit

Constructors

View Source

LedBarGraph(IDigitalOutputPort[])

Create an LedBarGraph instance from an array of IDigitalOutputPort

Declaration
public LedBarGraph(IDigitalOutputPort[] ports)

Parameters

Type Name Description
IDigitalOutputPort[] ports
View Source

LedBarGraph(IIODevice, IPin[])

Create an LedBarGraph instance from an array of IPins

Declaration
public LedBarGraph(IIODevice device, IPin[] pins)

Parameters

Type Name Description
IIODevice device
IPin[] pins
View Source

LedBarGraph(IIODevice, IPin[], Single)

Create an LedBarGraph instance from an array of IPwnPin and a forwardVoltage for all LEDs in the bar graph

Declaration
public LedBarGraph(IIODevice device, IPin[] pins, float forwardVoltage)

Parameters

Type Name Description
IIODevice device
IPin[] pins
System.Single forwardVoltage

Fields

View Source

_isPwm

Declaration
protected bool _isPwm

Field Value

Type Description
System.Boolean
View Source

_leds

Declaration
protected Led[] _leds

Field Value

Type Description
Led[]
View Source

_pwmLeds

Declaration
protected PwmLed[] _pwmLeds

Field Value

Type Description
PwmLed[]

Properties

View Source

Count

The number of the LEDs in the bar graph

Declaration
public int Count { get; }

Property Value

Type Description
System.Int32
View Source

Percentage

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

Declaration
public float Percentage { set; }

Property Value

Type Description
System.Single

Methods

View Source

SetLed(Int32, Boolean)

Set the LED state

Declaration
public void SetLed(int index, bool isOn)

Parameters

Type Name Description
System.Int32 index

index of the LED

System.Boolean isOn
View Source

SetLedBrightness(Int32, Single)

Set the brightness of an individual LED when using PWM

Declaration
public void SetLedBrightness(int index, float brightness)

Parameters

Type Name Description
System.Int32 index
System.Single brightness