WS2812 together with RGB5050

This is a small arduino project, especially for my office. The light for my desk is an LED stripe (WS2812 with RGB5050). So I’m able to change the color from each single LED. It’s great to need only three wire for all!

My little circuit consists of three potentiometer, nothing more. With each potentiometer I can change one color (the WS2812 needs a value between 0 and 255 for each color). I connect the potentiometer with the analog Input – A0 for red, A1 for green and A2 for blue.

I show you a little sketch …

WS2812

And this is the code:

// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h>
#endif




#define PIN 5

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 58

int r,g,b;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

pixels.begin(); // This initializes the NeoPixel library.
 
 for(int i=0;i<NUMPIXELS;i++){
 pixels.setPixelColor(i, pixels.Color(0,0,0)); 
 pixels.show(); 
 }

r = analogRead(A0)/4;
 g = analogRead(A1)/4;
 b = analogRead(A2)/4;

// rot from left to right
 for(int i=0;i<NUMPIXELS;i++){ 
 pixels.setPixelColor(i, pixels.Color(100,0,0)); 
 pixels.show(); 
 delay(50);
 }
 // blue from right to left
 for(int i=NUMPIXELS;i>=0;i--){ 
 pixels.setPixelColor(i, pixels.Color(0,0,100)); 
 pixels.show(); 
 delay(50);
 }
 //green from left to right
 for(int i=0;i<NUMPIXELS;i++){ 
 pixels.setPixelColor(i, pixels.Color(0,100,0)); 
 pixels.show(); 
 delay(50);
 }
 // white from right to left
 for(int i=NUMPIXELS;i>=0;i--){ 
 pixels.setPixelColor(i, pixels.Color(100,100,100)); 
 pixels.show(); 
 delay(50);
 } 
 delay(100);
}

void loop() {
 r = analogRead(A0)/4;
 g = analogRead(A1)/4;
 b = analogRead(A2)/4;
 
 for(int i=0;i<NUMPIXELS;i++){ 
 pixels.setPixelColor(i, pixels.Color(r,g,b)); 
 pixels.show(); 
 }
 delay(100);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s