LED – RGB Farbstreifen

Kleine LED Leuchten bieten die Möglichkeit das additive Farspektrum abzubilden. (RGB) Jeder Farkanal kann dieszbezüglich einzeln angesteuert werden. Die farbigen LED sind einzeln erhältlich oder können wie im Beispiel unten in Kombination mit den Arduino Board verwendet werden.
Ein Demonstrationsvideo findet sich unter folgenden Adresse:
http://hacknmod.com/hack/incredible-colorful-rgb-led-light-strip/de/
Natürlich gibt es schon eine gut dokumentierte Open Source Lösung, die sich unter folgender Adresse befindet:
http://code.google.com/p/ledstrip/
[yotube=http://www.youtube.com/watch?v=PrBnERpcLjA]
———————————————————————————————-

Hier ein sehr interessantes Projekt, das eine Kombination mehrerer Sensoriken aufzeigt:
http://nezoomie.wordpress.com/2009/11/17/arduino-rgb-mood-lamp-touch-tiltable-potentiometers/
——————————————————————————————–
Ein entsprechendes Arduino Skript für eine kontrollierbare RGB LED ist:
————————————————————————————————-
[sourcecode language="java"]
#define BLUE 1
#define GREEN 2
#define RED 3
int portLedBlau1 = 3;
int portLedBlau2 = 6;
int portLedGruen = 9;
int portLedRot = 5;
int portLichtSensor = 5;
int logarithmus[64] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,16,18,20,22,25,28,30,33,36,
39,42,46,53,56,60,64,68,72,77,81,86,90,95,100,105,110,116,121,
127,132,138,144,150,156,163,169,176,182,189,196,203,210,218,225,
233,240,248,255};
void setup()
{
pinMode(portLedBlau1, OUTPUT);
pinMode(portLedBlau2, OUTPUT);
pinMode(portLedGruen, OUTPUT);
pinMode(portLedRot, OUTPUT);
}
/**
* Liest den Lichtsensot aus und setzt je nach Wert eine Farbe
*/
void loop()
{
int licht = analogRead(portLichtSensor) / 4;
setColorByValue(licht);
}
/**
* Sucht für einen Wert zwischen 1 und 255 eine Farbe aus dem Farbkreis
* @param integer value (0-255)
*/
void setColorByValue(int value)
{
int blue;
int green;
int red;
if(value < 64) // Rot zu Gruen
{
red = 63 – value;
green = value;
blue = 0;
}
else if(value < 128) // Gruen nach Blau
{
red = 0;
green = 127 – value;
blue = value – 64;
}
else if(value < 192) // Blau nach Rot
{
red = value – 128;
green = 0;
blue = 191 – value;
}
else // Rot nach Weiß
{
red = 63;
green = 255 – value;
blue = 255 – value;
}
setColor(logarithmus[red], logarithmus[green], logarithmus[blue]);
}
/**
* Stellt die LED auf eine Farbe um
* @param integer blue (0-255)
* @param integer green(0-255)
* @param integer blue(0-255)
*/
void setColor(int red, int green, int blue)
{
setLed(BLUE, blue);
setLed(GREEN, green);
setLed(RED, red);
}
/**
* Setzt die LEDs einer Farbe (bzw. 2 für Blau)
* @param integer (1-3) BLUE = 1, GREEN = 2, RED = 3
*/
void setLed(int color, int intensity)
{
switch(color)
{
case BLUE:
analogWrite(portLedBlau1, intensity);
analogWrite(portLedBlau2, intensity);
break;
case GREEN:
analogWrite(portLedGruen, intensity);
break;
case RED:
analogWrite(portLedRot, intensity);
break;
}
}
[/sourcecode]
Ein alternatives Skript ist hier:
[sourcecode language="java"]
int rpin = 9;
int gpin = 10;
int bpin = 11;
//function prototypes
void solid(int r, int g, int b, int t);
void fade(int r1, int g1, int b1, int r2, int g2, int b2, int t);
void setup()
{
//empty
}
void loop()
{
//colour sequence instructions
//Example sequence one: Rainbow fade over 15 seconds:
fade(255,0,0,0,255,0,5000); //fade from red to green over 5 seconds
fade(0,255,0,0,0,255,5000); //fade from green to blue over 5 seconds
fade(0,0,255,255,0,0,5000); //fade from blue to red over 5 seconds
}
//function holds RGB values for time t milliseconds
void solid(int r, int g, int b, int t)
{
//map values – arduino is sinking current, not sourcing it
r = map(r, 0, 255, 255, 0);
g = map(g, 0, 255, 255, 0);
b = map(b, 0, 255, 255, 0);
//output
analogWrite(rpin,r);
analogWrite(gpin,g);
analogWrite(bpin,b);
//hold at this colour set for t ms
delay(t);
}
//function fades between two RGB values over fade time period t
//maximum value of fade time = 30 seconds before gradient values
//get too small for floating point math to work? replace floats
//with doubles to remedy this?
void fade(int r1, int g1, int b1, int r2, int g2, int b2, int t)
{
float r_float1, g_float1, b_float1;
float r_float2, g_float2, b_float2;
float grad_r, grad_g, grad_b;
float output_r, output_g, output_b;
//declare integer RGB values as float values
r_float1 = (float) r1;
g_float1 = (float) g1;
b_float1 = (float) b1;
r_float2 = (float) r2;
g_float2 = (float) g2;
b_float2 = (float) b2;
//calculate rates of change of R, G, and B values
grad_r = (r_float2-r_float1)/t;
grad_g = (g_float2-g_float1)/t;
grad_b = (b_float2-b_float1)/t;
//loop round, incrementing time value "i"
for ( float i=0; i<=t; i++ )
{
output_r = r_float1 + grad_r*i;
output_g = g_float1 + grad_g*i;
output_b = b_float1 + grad_b*i;
//map values – arduino is sinking current, not sourcing it
output_r = map (output_r,0,255,255,0);
output_g = map (output_g,0,255,255,0);
output_b = map (output_b,0,255,255,0);
//output
analogWrite(rpin, (int)output_r);
analogWrite(gpin, (int)output_g);
analogWrite(bpin, (int)output_b);
//hold at this colour set for 1ms
delay(1);
}
}
[/sourcecode]
Die Farbkanäle lassen sich natürlich auch per Tilt kontrollieren:
http://www.instructables.com/id/Wireless_Accelerometer_Controlled_rgb_LEDs/