Remarks

Led
Status
Source code GitHub
NuGet package

An LED is a diode (a component that attempts to let current flow only one way through it) that emits light when voltage is applied to it. Because it is a diode, it only works when a voltage is applied in one direction.

LEDs commonly have one lead longer (the Cathode) than the other (the Anode). The longer cathode leg indicates that it should be connected to the positive (+) side of a circuit.

Code Example

The following example shows how to turn on and off the LED using the IsOn property, and uses a StartBlink(onDuration, offDuration) API method to make the LED blink staying on for 500ms (0.5s) and off for 1000ms (1s):

public class LedApp : App<F7Micro, LedApp>
{
    public LedApp()
    {
        // create a new Led on pin 8
        var led = new Led(Device.CreateDigitalOutputPort(Device.Pins.D08));

        while (true)
        {
            led.IsOn = true;    // Led ON
            Thread.Sleep(3000); // 3 seconds
            led.IsOn = false;   // Led OFF
            Thread.Sleep(2000); // 2 seconds
            led.IsOn = true;    // Led ON
            Thread.Sleep(1000); // 1 second

            led.StartBlink(500, 1000);
            Thread.Sleep(5000); // 5 seconds
            led.Stop();
            Thread.Sleep(1500); // 1.5 seconds, ensure last blink cycle is complete
        }
    }
}

Sample projects available on GitHub

Wiring Example

Characteristic Locus
Inheritance System.Object > Led
Namespace Meadow.Foundation.Leds
Assembly Meadow.Foundation.dll

Syntax

public class Led : ILed

Constructors

Led(IDigitalOutputPort)

Creates a LED through a DigitalOutPutPort from an IO Expander

Declaration
public Led(IDigitalOutputPort port)

Parameters

Type Name Description
IDigitalOutputPort port

Led(IIODevice, IPin)

Creates a LED through a pin directly from the Digital IO of the board

Declaration
public Led(IIODevice device, IPin pin)

Parameters

Type Name Description
IIODevice device
IPin pin

Fields

_animationTask

Declaration
protected Task _animationTask

Field Value

Type Description
System.Threading.Tasks.Task

_isOn

Declaration
protected bool _isOn

Field Value

Type Description
System.Boolean

_running

Declaration
protected bool _running

Field Value

Type Description
System.Boolean

Properties

IsOn

Gets or sets a value indicating whether this Led is on.

Declaration
public bool IsOn { get; set; }

Property Value

Type Description
System.Boolean

true if is on; otherwise, false.

Port

Gets the port that is driving the LED

Declaration
public IDigitalOutputPort Port { get; protected set; }

Property Value

Type Description
IDigitalOutputPort

The port

Methods

Blink animation that turns the LED on and off based on the OnDuration and offDuration values in ms

Declaration
public void StartBlink(uint onDuration = 200U, uint offDuration = 200U)

Parameters

Type Name Description
System.UInt32 onDuration
System.UInt32 offDuration

Stop()

Stops the LED when its blinking and/or turns it off.

Declaration
public void Stop()