Remarks

Pca9685
Status
Source code GitHub
NuGet package

Code Example

public class MeadowApp : App<F7Micro, MeadowApp>
{
    Apa102 apa102;

    public MeadowApp()
    {
        Initialize();
        Run();
    }

    void Initialize()
    {
        Console.WriteLine("Initialize hardware...");
        ISpiBus spiBus = Device.CreateSpiBus();

        //Not used but is need to create the SPI Peripheral
        IDigitalOutputPort spiPeriphChipSelect = Device.CreateDigitalOutputPort(Device.Pins.D04);
        apa102 = new Apa102(spiBus, spiPeriphChipSelect, 10, Apa102.PixelOrder.BGR);
    }

    void Run()
    {
        Console.WriteLine("Run...");
        apa102.Clear();
        apa102.Show();

        Thread.Sleep(2000);
        apa102.SetLed(0, Color.Red, 0.5f);
        apa102.SetLed(1, Color.White);
        apa102.SetLed(2, Color.Blue);

        Thread.Sleep(2000);
        apa102.Show();

        Thread.Sleep(2000);
        apa102.AutoWrite = true;
        apa102.SetLed(0, Color.Green);
        apa102.SetLed(1, Color.Yellow);
        apa102.SetLed(2, Color.Pink);

        Thread.Sleep(5000);
        apa102.Clear();
    }
}
Characteristic Locus
Inheritance System.Object > Apa102
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 Apa102.dll

Syntax

public class Apa102

Constructors

Apa102(ISpiBus, IDigitalOutputPort, UInt32, Apa102.PixelOrder, Boolean)

Declaration
public Apa102(ISpiBus spiBus, IDigitalOutputPort chipSelect, uint numberOfLeds, Apa102.PixelOrder pixelOrder = Apa102.PixelOrder.BGR, bool autoWrite = false)

Parameters

Type Name Description
ISpiBus spiBus

The SPI bus

IDigitalOutputPort chipSelect

THe SPI chip select pin. Not used but need for creating the SPI Peripheral

System.UInt32 numberOfLeds

The number of APA102 LEDs to control

Apa102.PixelOrder pixelOrder

Set the pixel order on the LEDs - different strips implement this differently

System.Boolean autoWrite

Transmit any LED changes right away

Fields

spiPeripheral

Declaration
protected ISpiPeripheral spiPeripheral

Field Value

Type Description
ISpiPeripheral

Properties

AutoWrite

Declaration
public bool AutoWrite { get; set; }

Property Value

Type Description
System.Boolean

Brightness

Declaration
public float Brightness { get; set; }

Property Value

Type Description
System.Single

NumberOfLeds

Declaration
public uint NumberOfLeds { get; }

Property Value

Type Description
System.UInt32

Methods

Clear(Boolean)

Turn off all the Leds

Declaration
public virtual void Clear(bool autoWrite = false)

Parameters

Type Name Description
System.Boolean autoWrite

SetLed(UInt32, Color)

Set the color of the specified LED

Declaration
public virtual void SetLed(uint index, Color color)

Parameters

Type Name Description
System.UInt32 index

Index of the LED to change

Color color

The color

SetLed(UInt32, Color, Single)

Set the color of the specified LED

Declaration
public virtual void SetLed(uint index, Color color, float brightness = 1F)

Parameters

Type Name Description
System.UInt32 index

Index of the LED to change

Color color

The color

System.Single brightness

The brighrness 0.0 - 1.0f

SetLed(UInt32, Byte[])

Set the color of the specified LED

Declaration
public virtual void SetLed(uint index, byte[] rgb)

Parameters

Type Name Description
System.UInt32 index

Index of the LED to change

System.Byte[] rgb

Byte array representing the color RGB values. byte[0] = Red, byte[1] = Green, byte[2] = Blue

SetLed(UInt32, Byte[], Single)

Set the color of the specified LED

Declaration
public virtual void SetLed(uint index, byte[] rgb, float brightness = 1F)

Parameters

Type Name Description
System.UInt32 index

Index of the LED to change

System.Byte[] rgb

Byte array representing the color RGB values. byte[0] = Red, byte[1] = Green, byte[2] = Blue

System.Single brightness

The brighrness 0.0 - 1.0f

Show()

Transmit the changes to the LEDs

Declaration
public virtual void Show()