Library to control NeoPixel strings of RGB leds

Dependencies:   PixelArray

Dependents:   NeoPixelI2cSlave NeoPixelI2cSlave

neopixel_string.cpp

Committer:
dwini
Date:
2015-10-25
Revision:
0:66a5d46a740f
Child:
2:bb9ebad05691

File content as of revision 0:66a5d46a740f:

#include "neopixel_string.h"

NeoPixelString::NeoPixelString(PinName spi_pin, unsigned int length) : PixelArray(spi_pin) {
    this->length = length;
    pixels = new neopixel::Pixel[length];     // Actual buffer of colors
    
    // Clear all
    update(Colors::Black);
}

void NeoPixelString::update(neopixel::Pixel singlecolor) {
    for (unsigned int i = 0; i < length; i++) {
        pixels[i] = singlecolor;
    }
    PixelArray::update(pixels, length);
}

void NeoPixelString::diagnose(void) {
    update(Colors::Black);
    wait(1);
    for (int i = 0; i < 5; i++) {
        update(ColorAdjuster::intensity(Colors::Red, 5));
        wait(0.5);
        update(ColorAdjuster::intensity(Colors::Green, 5));
        wait(0.5);
        update(ColorAdjuster::intensity(Colors::Blue, 5));
        wait(0.5);
    }
    
    update(Colors::Black);
    for (unsigned int i = 0; i < length; i++) {
        pixels[i] = ColorAdjuster::intensity(Colors::White, 5);
        PixelArray::update(pixels, length);
        wait(0.1);
    }
}