3.3 NeoPixel Stick Functions

The Adafruit NeoPixel Stick uses a custom-written set of six foundational functions that allow the NeoPixel Stick to turn on or off all its LEDs at the correct time. While there are other types of LED programming solutions, this one is primarily based on software as opposed to hardware.

The onePulse() function does not have any inputs and sends a 1 in the correct timing to the LED DIN pin. Likewise, the zeroPulse() function does not have any inputs and sends a 0 in the correct timing to the LED DIN pin.

The LED_send_byte(K) function uses an unsigned character (char) K as an input. This input, which is a byte of data, utilizes a series of IF-ELSE statements to send the correct 1 or 0 sequence that corresponds to each bit in the K byte.

The LED_Array(R,G,B) function uses three unsigned chars R, G, and B as inputs. Each of these inputs need to be a byte long since it contains the value of the red, green, or blue component of the LED. This function also sends the data in the correct order for the NeoPixel Stick to understand which is green, then red, then blue.

The RED() function has no inputs and sends the color red to all 8 LEDs on the LED Strip. This function can be renamed to other colors and be adapted to any other color.

The OFF() function has no inputs and turns all of the LEDs off. Additional custom functions can be created to cause a blink feature by using the RED() function and/or adapted functions, the OFF() function, and the __delay_ms(x) line of code, where x specifies the delay in milliseconds.

An example blink function, named RED_BLINK_500ms, is shown in Blink Code Example.

Blink Code Example

    //All 8 LEDs blink Red and then turn off at a 500 ms interval
void RED_BLINK_500ms()
{
        RED();
        __delay_ms(500);
        OFF();
        __delay_ms(500);
}