Elmwood no more, long live Elmwood! Elmwood Electronics and PiShop are now together!
Please order via PiShop.ca, as we are no longer taking orders through this site.
More details are in our blog!

NeoPixel Colour Picker

September 16, 2016

NeoPixel Colour Picker

The lighting in my garage was pretty poor, and since we sell lots of NeoPixels, naturally I had a strip lying around!  So I figured NeoPixel LED's would be an efficient and bright way to light the garage!

The lighting in my garage was pretty poor, and since we sell lots of NeoPixels, naturally I had a strip lying around!  So I figured NeoPixel LED's would be an efficient and bright way to light the garage!

Of course I didn't want just an on / off switch, it would be way more fun to be able to pick colours.  So, I grabbed a set of round tactile buttons, and luckily there were red, green, blue, yellow, and gray.  I decided red, green and blue would control the colour, yellow would be "white", and gray would be off.

To control everything I used a Pro Trinket 5V, which is like an Arduino Mini with more pins and USB.  I  used 5 input pins for the switches and one output pin for the NeoPixel Strip.

The buttons are wired to ground, meaning, when you press the button the switch closes and sends a ground (LOW) signal to the Trinket.  I wrote the code so it constantly loops to see what buttons are pressed.  What's nice about this is that I was able to have it see if more than one button is pressed, so you can make more than just Red, Green and Blue!

Programming the Pro Trinket is easy via a microUSB cable.  More details on programming the Pro Trinket can be found in the Adafruit Learning System.

On my first prototype I used a basic solderless breadboard with some hookup wires, but to really finish it off i used an Adafruit Perma-Proto board.  This was a good choice because i could easily mount it to the wall and wire up all the connections.  

Adafruit has a great tutorial on how to use NeoPixels, so I will not get into much detail on how they work.  The important thing to know is that they need a good amount of power if you are using a bunch of them, so I used a hefty 10 amp 5V power supply to run 150 NeoPixels.  Also pay attention to the guide's suggestions regarding capacitors and resistors to avoid damaging your NeoPixels.

You'll want to make sure you install Adafruit's NeoPixel Library and also set your Arduino IDE up for the Pro Trinket.

See below for my Arduino code.  Basically I just took the Adafruit NeoPixel strandtest code and added some logic for the buttons.  Super simple!  

 

 

#include <Adafruit_NeoPixel.h>

#define PIN 4
#define HIGH 1
#define LOW 0

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

// constants won't change. They're used here to
// set pin numbers:
const int offPin = 10; // the number of the pushbutton pin
const int whitePin = 13;
const int greenPin = 6;
const int redPin = 8;
const int bluePin = 5;

// variables will change:
int offState = 0; // variable for reading the pushbutton status
int whiteState = 0;
int greenState = 0;
int redState = 0;
int blueState = 0;
int pixelSpeed = 10;

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(offPin, INPUT_PULLUP);
pinMode(whitePin, INPUT_PULLUP);
pinMode(greenPin, INPUT_PULLUP);
pinMode(bluePin, INPUT_PULLUP);
pinMode(redPin, INPUT_PULLUP);
pinMode(13, OUTPUT);
}

void loop() {
// Some example procedures showing how to display to the pixels:
whiteState = digitalRead(whitePin);
offState = digitalRead(offPin);
greenState = digitalRead (greenPin);
blueState = digitalRead (bluePin);
redState = digitalRead (redPin);
if (greenState == LOW | redState == LOW | blueState == LOW) {
colorWipe(strip.Color(255 * (1-redState), 255 * (1-greenState), 255 * (1-blueState)), pixelSpeed); // RGB
}
else if (whiteState == LOW) {
colorWipe(strip.Color(255, 255, 255), pixelSpeed); // WHITE
}
else if (offState == LOW) {
colorWipe(strip.Color(0, 0, 0), pixelSpeed); // WHITE
}
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}

 

 





Also in News

Elmwood no more, long live Elmwood! Elmwood Electronics and PiShop are now together!

October 03, 2022

Elmwood no more, long live Elmwood! Elmwood Electronics and PiShop are now together! Please see our blog for more info.

Continue Reading

Adding RGB LEDs to an illuminated arcade button

March 14, 2022

Continue Reading

We Made a Media Controller!

October 12, 2021

Continue Reading