Skip to content

Latest commit

 

History

History
75 lines (57 loc) · 1.9 KB

File metadata and controls

75 lines (57 loc) · 1.9 KB

Ws28xx LED drivers

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.

Documentation

Board

WS2812B

image

Usage

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();

// Must specify pin functions on ESP32
Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI);
Configuration.SetPinFunction(19, DeviceFunction.SPI2_MISO);
Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK);
Configuration.SetPinFunction(22, DeviceFunction.ADC1_CH10);

// Using VSPI on bus 2 for ESP32 and pin 22 for chipselect
SpiConnectionSettings settings = new(2, 22)
{
    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();
    }
}