Tuesday, 12 August 2014

Simple Arduino NeoPixel Sketch

I found that the Adafruit  NeoPixel  Arduino examples  were rather over complicated for the beginner . So I wrote a simple sketch, which does nothing more that light  Red, Green and Blue on 3 separate pixels. Hopefully this should make it easier to follow the code, especially if all you want is a single lit pixel  at a certain position around the ring , or if you are using a single standalone WS2812  in one of your own projects.

 Simple NeoPixel Sketch
 Rupert Hirst 2014

#include <Adafruit_NeoPixel.h>

//  which pin is used on the arduino?
#define PIN 6

// Total Number of Pixels
#define NUMofPIXELS 16

// setup the NeoPixel library, number of pixels and pin .
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMofPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
pixels.setBrightness(255); // Global Brightness
  pixels.begin(); // initializes the NeoPixel library.

void loop() {
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    // pixels.setPixelColor(Pixel number "0" is the first, red, green, blue);
     // http://www.rapidtables.com/web/color/RGB_Color.htm
   pixels.setPixelColor(0,pixels.Color(255,0,0)); // RED
   pixels.setPixelColor(1,pixels.Color(0,255,0)); // GREEN
   pixels.setPixelColor(2,pixels.Color(0,0,255)); // BLUE

    pixels.show(); //  sends the value, when the color has been set