Search Results for

    Show / Hide Table of Contents

    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

    • WS2812B: Datasheet
    • WS2815B: Datasheet
    • WS2808: Datasheet
    • SK6812: Datasheet
    • Neo pixels guide
    • Neo pixels x8 stick

    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();
        }
    }
    
    • Improve this Doc
    In This Article
    Back to top Copyright © 2023 nanoFramework Contributors
    Generated by DocFX