David Silvera
Published © CC BY

WS2812b and Spresense

How to implement easily a WS2812b strip with new Sony Spresense Board. It is the simplest tutorial!

BeginnerProtip1 hour71
WS2812b and Spresense

Things used in this project

Story

Read more

Schematics

Connections

Don't forget to connect common ground cable between board and DC source.

Code

Testin NeoPixel Leds

Arduino
Just download and run in your board.
#include <SpresenseNeoPixel.h>

// const uint16_t PIN = 6;
const uint16_t PIN = 8;
const uint16_t NUM_PIXELS = 12;
SpresenseNeoPixel<PIN, NUM_PIXELS> neopixel;

void setup()
{
    Serial.begin(115200);
    neopixel.clear();
    neopixel.framerate(40); // default framerate is 40[fps]
    delay(1000);

    Serial.println("start");
}

void loop()
{
    static uint32_t prev_ms = millis();
    static uint8_t state = 0;
    if (millis() > prev_ms + 1000)
    {
        Serial.println("change color");

        switch (state)
        {
            case 0:
                neopixel.set(state,128, 0, 0);
                break;
            case 1:
                neopixel.set(state+1,150, 0, 0);
                break;
            case 2:
                neopixel.set(state-1,0, 128, 0);
                break;
            case 3:
                neopixel.set(state++,0, 150, 0);
                break;
            case 4:
                neopixel.set(state--,0, 0, 128);
                break;
            case 5:
                neopixel.set(state,0, 0, 150);
                break;
            case 6:
                neopixel.set(state,0, 150, 255);
                break;
            case 7:
                neopixel.set(11,150, 0, 150);
                break;
            case 8:
            default:
                neopixel.set(0, 0, 0);
                break;
        }
        state = (state + 1) % 9;
        prev_ms = millis();
    }

    neopixel.show(); // automatically control framerate to desired fps
}

Credits

David Silvera

David Silvera

2 projects • 0 followers

Comments