/* // RGB Test code, originally from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226962662 // He comments: // This code is designed to give a bias towards stronger primary and secondary colours rather than pastels. // It is also designed to sometimes make the colours fade away to off. // Playing around with the random number generator at the bottom of thh code will affect the colours // you get or making it just do random(256) will make it not go off at all. // Mike Mc, 2008 Mods & commenting for use with the Solarbotics Star Controller RGB LED Kit by Dave Hrynkw, Solarbotics Ltd., Aug 15 2012 - Connect your Star Controller to the Arduino using the RGB pins to 9, 10, and 11 respectively. - Either power the Star Controller directly from 5 to 12VDC, or via the Arduino's Power "Vin" line (assuming it's below 12VDC) - Load the code to your Arduino, and prepare to be dazzled by an RGB color mix! - Run the Terminal program, so you can see what RGB values are being used */ // Set the FROM and TO RGB color and the increment arrays float RGB1[3]; float RGB2[3]; float INC[3]; // Set the RGB integer values int red, green, blue; //Set the Pins int RedPin = 9; int GreenPin = 10; int BluePin = 11; void setup() { Serial.begin(9600); // Optional for debugging randomSeed(analogRead(0)); // Use noise to set the seed for (int x=0; x<3; x++) { // Set the To / From RGB array values RGB1[x] = random(256); RGB2[x] = random(256); } } void loop() { randomSeed(analogRead(0)); // Use noise to set the seed for (int x=0; x<3; x++) { INC[x] = (RGB1[x] - RGB2[x]) / 256; } // Set the increment valuse arrays for each of the colors for (int x=0; x<256; x++) { // Let's make some colors go, in 256 steps! red = int(RGB1[0]); // Read out the RGB values out of the array green = int(RGB1[1]); blue = int(RGB1[2]); Serial.print("RGB = "); // Print them out. Couldn't get them to concatenate any other way Serial.print(red); Serial.print(", "); Serial.print(green); Serial.print(", "); Serial.println(blue); analogWrite (RedPin, red); // Write the values out to the pins analogWrite (GreenPin, green); analogWrite (BluePin, blue); delay(10); for (int x=0; x<3; x++) { //Decrement each array variable by the increment array variable RGB1[x] -= INC[x];} } for (int x=0; x<3; x++) { // Change the 2nd RGB color elements in the array RGB2[x] = random(956)-700; // Pick num between 0 and 956, force below 256. RGB2[x] = constrain(RGB2[x], 0, 255); // Make sure it's above zero by forcing the value to fit between 0 and 255 } }