Fandt lige denne her kode, som ser ud til at virke ganske glimrende, nu skal jeg bare have en RGB Led på, så jeg bedre kan se effekten..
// 2009 Kenneth Finnegan
// kennethfinnegan.blogspot.com
// Pins. Must be PWM pins.
#define REDLED 3
#define BLUELED 5
#define GREENLED 6
// Can't be higher than 255
#define MAXBRIGHT 200
// s[tate] t[arget] colors
byte s[3] = {0}, t[3] = {0};
void setup() {
// Make the random MORE RANDOM!
randomSeed(analogRead(0));
// Initialization wiring check
// You should see RED, BLUE, then GREEN.
// If you don't, then you ballsed something up.
analogWrite(REDLED, MAXBRIGHT);
delay(1000);
analogWrite(REDLED, 0);
analogWrite(BLUELED, MAXBRIGHT);
delay(1000);
analogWrite(BLUELED, 0);
analogWrite(GREENLED, MAXBRIGHT);
delay(1000);
analogWrite(GREENLED, 0);
}
void loop() {
byte i, offset;
// Select the next target color
// Start from a random one of the three colors to prevent
// the cycle from being red biased.
offset = random(3);
t[offset] = random(MAXBRIGHT);
t[(offset+1)%3] = random(MAXBRIGHT - t[offset]);
t[(offset+2)%3] = MAXBRIGHT - t[offset] - t[(offset+1)%3];
// Slowly drift to the new target color 1 at a time until
// it has been reached
while(s[0]!=t[0] || s[1]!=t[1] || s[2] != t[2]) {
for (i = 0; i<3; i++) {
if (s[i] > t[i]) {
s[i] = s[i] - 1;
} else if (s[i] < t[i]) {
s[i] = s[i] + 1;
}
analogWrite(REDLED, s[0]);
analogWrite(BLUELED, s[1]);
analogWrite(GREENLED, s[2]);
delay(10);
}
}
analogWrite(REDLED, s[0]);
analogWrite(BLUELED, s[1]);
analogWrite(GREENLED, s[2]);
// Let the viewer enjoy the new color before
// selecting the next target color.
delay(2000);
}