Remarks

Apa102
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Apa102

Code Example

Apa102 apa102;
int numberOfLeds = 49;
float maxBrightness = 0.25f;

public MeadowApp()
{
    Console.WriteLine("Initialize hardware...");
    apa102 = new Apa102(Device.CreateSpiBus(Apa102.DefaultSpiBusSpeed), numberOfLeds, Apa102.PixelOrder.BGR);

    apa102.Clear();

    apa102.SetLed(index: 0, color: Color.Red, brightness: 0.5f);
    apa102.SetLed(index: 1, color: Color.Purple, brightness: 0.6f);
    apa102.SetLed(index: 2, color: Color.Blue, brightness: 0.7f);
    apa102.SetLed(index: 3, color: Color.Green, brightness: 0.8f);
    apa102.SetLed(index: 4, color: Color.Yellow, brightness: 0.9f);
    apa102.SetLed(index: 5, color: Color.Orange, brightness: 1.0f);

    apa102.Show();
}

Sample project(s) available on GitHub

Wiring Example

To wire a Apa102 to your Meadow board, connect the following:

Apa102 Meadow Pin
GND GND
CI SCK
DI MOSI
VCC 5V

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object > Apa102
Implements IApa102 IGraphicsDisplay
Namespace Meadow.Foundation.Leds
Assembly Apa102.dll

Syntax

public class Apa102 : object, IApa102, IGraphicsDisplay

Constructors

Apa102(IMeadowDevice, ISpiBus, IPin, Int32, Apa102.PixelOrder)

Creates a new APA102 object

Declaration
public Apa102(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, int numberOfLeds, Apa102.PixelOrder pixelOrder = Apa102.PixelOrder.BGR)

Parameters

Type Name Description
IMeadowDevice device

IMeadowDevice

ISpiBus spiBus

SPI bus

IPin chipSelectPin

Chip select pin

System.Int32 numberOfLeds

Number of leds

Apa102.PixelOrder pixelOrder

Pixel color order

Apa102(IMeadowDevice, ISpiBus, IPin, Int32, Int32, Apa102.PixelOrder)

Creates a new APA102 object

Declaration
public Apa102(IMeadowDevice device, ISpiBus spiBus, IPin chipSelectPin, int width, int height, Apa102.PixelOrder pixelOrder = Apa102.PixelOrder.BGR)

Parameters

Type Name Description
IMeadowDevice device

IMeadowDevice

ISpiBus spiBus

SPI bus

IPin chipSelectPin

Chip select pin

System.Int32 width

Width of led array

System.Int32 height

Height of led array

Apa102.PixelOrder pixelOrder

Pixel color order

Apa102(ISpiBus, Int32, Apa102.PixelOrder, IDigitalOutputPort)

Creates a new APA102 object

Declaration
public Apa102(ISpiBus spiBus, int numberOfLeds, Apa102.PixelOrder pixelOrder = Apa102.PixelOrder.BGR, IDigitalOutputPort chipSelectPort = null)

Parameters

Type Name Description
ISpiBus spiBus

SPI bus

System.Int32 numberOfLeds

Number of leds

Apa102.PixelOrder pixelOrder

Pixel color order

IDigitalOutputPort chipSelectPort

SPI chip select port (optional)

Apa102(ISpiBus, Int32, Int32, Apa102.PixelOrder, IDigitalOutputPort)

Creates a new APA102 object

Declaration
public Apa102(ISpiBus spiBus, int width, int height, Apa102.PixelOrder pixelOrder = Apa102.PixelOrder.BGR, IDigitalOutputPort chipSelectPort = null)

Parameters

Type Name Description
ISpiBus spiBus

SPI bus

System.Int32 width

Width of led array

System.Int32 height

Height of led array

Apa102.PixelOrder pixelOrder

Pixel color order

IDigitalOutputPort chipSelectPort

SPI chip select port (optional)

Fields

DefaultSpiBusSpeed

Default SPI bus speed

Declaration
public static Frequency DefaultSpiBusSpeed

Field Value

Type Description
Frequency

spiPeripheral

SpiPeripheral object

Declaration
protected ISpiPeripheral spiPeripheral

Field Value

Type Description
ISpiPeripheral

Properties

Brightness

Brightness

Declaration
public float Brightness { get; set; }

Property Value

Type Description
System.Single

ColorMode

Color mode of leds - 24bpp

Declaration
public ColorType ColorMode { get; }

Property Value

Type Description
ColorType

Height

Height of pixel array

Declaration
public int Height { get; }

Property Value

Type Description
System.Int32

IgnoreOutOfBoundsPixels

Ignore out of bounds pixels

Declaration
public bool IgnoreOutOfBoundsPixels { get; set; }

Property Value

Type Description
System.Boolean

NumberOfLeds

Total number of leds

Declaration
public int NumberOfLeds { get; }

Property Value

Type Description
System.Int32

Width

Width of pixel array

Declaration
public int Width { get; }

Property Value

Type Description
System.Int32

Methods

Clear(Boolean)

Turn off all the Leds

Declaration
public void Clear(bool update = false)

Parameters

Type Name Description
System.Boolean update

DrawBuffer(Int32, Int32, IDisplayBuffer)

Draw a buffer at the specified location

Declaration
public void DrawBuffer(int x, int y, IDisplayBuffer displayBuffer)

Parameters

Type Name Description
System.Int32 x

x position

System.Int32 y

y position

IDisplayBuffer displayBuffer

buffer to draw

DrawPixel(Int32, Int32, Color)

Draw pixel at location

Declaration
public void DrawPixel(int x, int y, Color color)

Parameters

Type Name Description
System.Int32 x

x position of pixel

System.Int32 y

y position of pixel

Color color

color of pixel

DrawPixel(Int32, Int32, Boolean)

Draw pixel at location

Declaration
public void DrawPixel(int x, int y, bool colored)

Parameters

Type Name Description
System.Int32 x

x position of pixel

System.Int32 y

y position of pixel

System.Boolean colored

if true draw white, if false draw black

Fill(Color, Boolean)

Fill the entire display buffer with a color

Declaration
public void Fill(Color clearColor, bool updateDisplay = false)

Parameters

Type Name Description
Color clearColor

color to fill

System.Boolean updateDisplay

update after fill

Fill(Int32, Int32, Int32, Int32, Color)

Fill a color in the specified region

Declaration
public void Fill(int x, int y, int width, int height, Color fillColor)

Parameters

Type Name Description
System.Int32 x

x position

System.Int32 y

y position

System.Int32 width

width to fill

System.Int32 height

height to fill

Color fillColor

color to fill

InvertPixel(Int32, Int32)

Invert pixel at location

Declaration
public void InvertPixel(int x, int y)

Parameters

Type Name Description
System.Int32 x

x position of pixel

System.Int32 y

y position of pixel

SetLed(Int32, Color)

Set the color of the specified LED

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

Parameters

Type Name Description
System.Int32 index

Index of the LED to change

Color color

The color

SetLed(Int32, Color, Single)

Set the color of the specified LED

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

Parameters

Type Name Description
System.Int32 index

Index of the LED to change

Color color

The color

System.Single brightness

The brighrness 0.0 - 1.0f

SetLed(Int32, Byte[])

Set the color of the specified LED

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

Parameters

Type Name Description
System.Int32 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(Int32, Byte[], Single)

Set the color of the specified LED

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

Parameters

Type Name Description
System.Int32 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 void Show()

Show(Int32, Int32, Int32, Int32)

Update APA102 with data in display buffer

Declaration
public void Show(int left, int top, int right, int bottom)

Parameters

Type Name Description
System.Int32 left

left

System.Int32 top

top

System.Int32 right

right

System.Int32 bottom

bottom