This binding allows you to update the RGB LEDs on Ws28xx and based strips and matrices.
To see how to use the binding in code, see the sample.
- WS2812B: Datasheet
- WS2808: Datasheet
- Neo pixels guide
- Neo pixels x8 stick
using System;
using System.Collections.Generic;
using System.Device.Spi;
using System.Drawing;
using Iot.Device.Graphics;
using Iot.Device.Ws28xx;
// Configure the count of pixels
const int Count = 8;
Console.Clear();
SpiConnectionSettings settings = new(0, 0)
{
ClockFrequency = 2_400_000,
Mode = SpiMode.Mode0,
DataBitLength = 8
};
using SpiDevice spi = SpiDevice.Create(settings);
Ws28xx neo = new Ws2808(spi, count);
//Ws28xx neo = new Ws2812b(spi, Count);
while (true)
{
Rainbow(neo, Count);
System.Threading.Thread.Sleep(100);
}
void Rainbow(Ws28xx neo, int count, int iterations = 1)
{
BitmapImage img = neo.Image;
for (var i = 0; i < 255 * iterations; i++)
{
for (var j = 0; j < count; j++)
{
img.SetPixel(j, 0, Wheel((i + j) & 255));
}
neo.Update();
}
}
- Make sure spi is enabled
dtparam=spi=on
- Make sure SPI don't change speed fix the core clock:
core_freq=250
core_freq_min=250