It still needs a lot of tweaking, and after I get the colors right, I'll slow it down as well.
I also need to figure out how to program it to jump it to a certain point, as well as be able to pause it.
The Arduino code in it's majority is not mine. I have made several changes to it, but most of it was a copy/paste from another Arduino code. I'll provide the link if I can find it again.
So without further ado, here it is!
http://youtu.be/UysoNEStVc8
(Don't be scared by the Unitrack, I'm still handlaying, this is just my quick and easy testbed layout for trying out numerous things and running trains while life has the modules on hold.

Here's a visual of a 2 channel circuit that could be expanded upon.
Attachment 58451
Components Required:
LED Strips - at least one RGB, and I also used warm white and cool white strips.
12V Power supply - make sure it has enough amperage to power all the LED strips. I used a 20 amp for 6 strips.
Arduino UNO - I used an UNO, as it supports up to 6 PWM channels. The Mega has 12, if more are needed.
MOSFETs - I used these: Link - I'm also using these heatsinks with them: Link
Breadboard - Since I didn't want to have a custom board made, I used this protoboard. Link
Assembly:
I used the diagrams at this site to assist in assembling the components. http://bildr.org/2012/03/rfp30n06le-arduino/
(All references here to the MOSFET's are as viewed from the side with the lettering)
Make sure everything is powered off before beginning.
1. Connect all the MOSFETS to the board.
2. Connect a 10K resistor to the left pin of a MOSFET. Connect the other side of the resistor to the right pin of the same MOSFET. Repeat for all the MOSFETs.
3. Connect the Arduino pin 9 to the left pin of the MOSFET that will control the red LEDs.
Repeat for the Arduino pins 10 and 11 to the left pins of the Green and Blue MOSFETs respectively.
If desired, connect Arduino pins 3 and 5 to the left pins of the Cool White and Warm White MOSFETs respectively.
Guide:
Cool White - pin 3
Warm White - pin 5
Red - pin 9
Green - pin 10
Blue - pin 11
4. Connect the middle pins of the MOSFETs to the "-" of their respective LED strips.
5. Connect the Arduino GND to the power supply ground, and to the right pin of all the MOSFETs.
6. Connect the power supply "+" to the "+" of all the LED strips. This is USUALLY(always check!) the red wire on single color LED strips, and the black wire on RGB strips.
7. Plug the Arduino's USB cable into your computer USB port, and using the Arduino software, upload the following code to the Arduino. After it uploads, you can either leave the Arduino connected to the computer, or disconnect it and use a different USB power supply to power it.
Code:
/* * Code for cross-fading 3 LEDs, red, green and blue (RGB) * To create fades, you need to do two things: * 1. Describe the colors you want to be displayed * 2. List the order you want them to fade in * * DESCRIBING A COLOR: * A color is just an array of three percentages, 0-100, * controlling the red, green and blue LEDs * * Red is the red LED at full, blue and green off * int red = { 100, 0, 0 } * Dim white is all three LEDs at 30% * int dimWhite = {30, 30, 30} * etc. * * Some common colors are provided below, or make your own * * LISTING THE ORDER: * In the main part of the program, you need to list the order * you want to colors to appear in, e.g. * crossFade(red); * crossFade(green); * crossFade(blue); * * Those colors will appear in that order, fading out of * one color and into the next * * In addition, there are 5 optional settings you can adjust: * 1. The initial color is set to black (so the first color fades in), but * you can set the initial color to be any other color * 2. The internal loop runs for 1020 interations; the 'wait' variable * sets the approximate duration of a single crossfade. In theory, * a 'wait' of 10 ms should make a crossFade of ~10 seconds. In * practice, the other functions the code is performing slow this * down to ~11 seconds on my board. YMMV. * 3. If 'repeat' is set to 0, the program will loop indefinitely. * if it is set to a number, it will loop that number of times, * then stop on the last color in the sequence. (Set 'return' to 1, * and make the last color black if you want it to fade out at the end.) * 4. There is an optional 'hold' variable, which pasues the * program for 'hold' milliseconds when a color is complete, * but before the next color starts. * 5. Set the DEBUG flag to 1 if you want debugging output to be * sent to the serial monitor. * * The internals of the program aren't complicated, but they * are a little fussy -- the inner workings are explained * below the main loop. */ //Input int sensorPin = A0; // select the input pin for the potentiometer for cycle speed int sensorValue = 20; // variable to store the value coming from the sensor int knob = 20; // Output int cwhPin = 3; // Cool White LED, connected to digital pin 3 int wwhPin = 5; // Warm White LED, connected to digital pin 5 //int auxPin = 6; // For other LED (if any) connected to digital pin 6 int redPin = 9; // Red LED, connected to digital pin 9 int grnPin = 10; // Green LED, connected to digital pin 10 int bluPin = 11; // Blue LED, connected to digital pin 11 // Color arrays int white[5] = { 100, 100, 100, 100, 100 }; int red[5] = { 100, 0, 0, 0, 0 }; int green[5] = { 0, 100, 0, 0, 0 }; int blue[5] = { 0, 0, 100, 0, 0 }; int yellow[5] = { 60, 50, 0, 0, 0 }; int dimWhite[5] = { 30, 30, 30, 30, 30 }; int black[5] = { 0, 0, 0, 0, 0 }; int dawnone[5] = { 98, 90, 70, 0, 0}; int dawntwo[5] = { 95, 20, 10, 0, 0 }; int dawnthree[5] = { 100, 57, 30, 70, 50 }; int carbonarc[5] = { 100, 97, 80 , 70, 100}; int sun[5] = { 100, 100, 80, 100, 100 }; int noon[5] = { 100, 100, 90, 100, 100 }; int duskone[5] = { 97, 85, 56, 0, 0 }; int dusktwo[5] = { 20, 40, 70, 0, 0 }; int blueone[5] = { 0, 10, 30, 0, 0 }; int bluetwo[5] = { 0, 0, 20, 0, 0 }; // etc. // Set initial color int redVal = black[0]; int grnVal = black[1]; int bluVal = black[2]; int cwhVal = black[3]; int wwhVal = black[4]; //int wait = sensorValue; // 10ms internal crossFade delay; increase for slower fades int hold = 0; // Optional hold when a color is complete, before the next crossFade int DEBUG = 1; // DEBUG counter; if set to 1, will write values back via serial int loopCount = 60; // How often should DEBUG report? int repeat = 0; // How many times should we loop before stopping? (0 for no stop) int j = 0; // Loop counter for repeat // Initialize color variables int prevR = redVal; int prevG = grnVal; int prevB = bluVal; int prevC = cwhVal; int prevW = wwhVal; // Set up the LED outputs void setup() { pinMode(redPin, OUTPUT); // sets the pins as output pinMode(grnPin, OUTPUT); pinMode(bluPin, OUTPUT); pinMode(cwhPin, OUTPUT); pinMode(wwhPin, OUTPUT); if (DEBUG) { // If we want to see values for debugging... Serial.begin(9600); // ...set up the serial ouput } } // Main program: list the order of crossfades void loop() // read the value from the sensor: { crossFade(dawntwo); crossFade(dawnone); crossFade(dawnthree); crossFade(carbonarc); crossFade(sun); crossFade(noon); crossFade(sun); crossFade(duskone); crossFade(black); crossFade(dusktwo); crossFade(blueone); crossFade(bluetwo); crossFade(black); crossFade(black); if (repeat) { // Do we loop a finite number of times? j += 1; if (j >= repeat) { // Are we there yet? exit(j); // If so, stop. } } sensorValue = analogRead(sensorPin); int wait = sensorValue; } /* BELOW THIS LINE IS THE MATH -- YOU SHOULDN'T NEED TO CHANGE THIS FOR THE BASICS * * The program works like this: * Imagine a crossfade that moves the red LED from 0-10, * the green from 0-5, and the blue from 10 to 7, in * ten steps. * We'd want to count the 10 steps and increase or * decrease color values in evenly stepped increments. * Imagine a + indicates raising a value by 1, and a - * equals lowering it. Our 10 step fade would look like: * * 1 2 3 4 5 6 7 8 9 10 * R + + + + + + + + + + * G + + + + + * B - - - * * The red rises from 0 to 10 in ten steps, the green from * 0-5 in 5 steps, and the blue falls from 10 to 7 in three steps. * * In the real program, the color percentages are converted to * 0-255 values, and there are 1020 steps (255*4). * * To figure out how big a step there should be between one up- or * down-tick of one of the LED values, we call calculateStep(), * which calculates the absolute gap between the start and end values, * and then divides that gap by 1020 to determine the size of the step * between adjustments in the value. */ int calculateStep(int prevValue, int endValue) { int step = endValue - prevValue; // What's the overall gap? if (step) { // If its non-zero, step = 1020/step; // divide by 1020 } return step; } /* The next function is calculateVal. When the loop value, i, * reaches the step size appropriate for one of the * colors, it increases or decreases the value of that color by 1. * (R, G, and B are each calculated separately.) */ int calculateVal(int step, int val, int i) { if ((step) && i % step == 0) { // If step is non-zero and its time to change a value, if (step > 0) { // increment the value if step is positive... val += 1; } else if (step < 0) { // ...or decrement it if step is negative val -= 1; } } // Defensive driving: make sure val stays in the range 0-255 if (val > 255) { val = 255; } else if (val < 0) { val = 0; } return val; } /* crossFade() converts the percentage colors to a * 0-255 range, then loops 1020 times, checking to see if * the value needs to be updated each time, then writing * the color values to the correct pins. */ void crossFade(int color[5]) { // Convert to 0-255 int R = (color[0] * 255) / 100; int G = (color[1] * 255) / 100; int B = (color[2] * 255) / 100; int C = (color[3] * 255) / 100; int W = (color[4] * 255) / 100; int stepR = calculateStep(prevR, R); int stepG = calculateStep(prevG, G); int stepB = calculateStep(prevB, B); int stepC = calculateStep(prevC, C); int stepW = calculateStep(prevW, W); for (int i = 0; i <= 1020; i++) { redVal = calculateVal(stepR, redVal, i); grnVal = calculateVal(stepG, grnVal, i); bluVal = calculateVal(stepB, bluVal, i); cwhVal = calculateVal(stepC, cwhVal, i); wwhVal = calculateVal(stepW, wwhVal, i); analogWrite(redPin, redVal); // Write current values to LED pins (added the "255 - " to each of these three to accomodate common anode LED. ex: analogWrite(wwhPin, 255 - wwhVal); ) Andrew Kyle analogWrite(grnPin, grnVal); analogWrite(bluPin, bluVal); analogWrite(cwhPin, cwhVal); analogWrite(wwhPin, wwhVal); delay(analogRead(sensorPin)); // Pause for 'wait' milliseconds before resuming the loop knob = analogRead(sensorPin); if (DEBUG) { // If we want serial output, print it at the if (i == 0 or i % loopCount == 0) { // beginning, and every loopCount times Serial.print("Loop/RGBCW: #"); Serial.print(i); Serial.print(" | "); Serial.print(redVal); Serial.print(" / "); Serial.print(grnVal); Serial.print(" / "); Serial.print(bluVal); Serial.print(" / "); Serial.print(cwhVal); Serial.print(" / "); Serial.println(wwhVal); Serial.print(knob); Serial.print(" , "); Serial.println(sensorPin); } DEBUG += 1; } } // Update current values for next loop prevR = redVal; prevG = grnVal; prevB = bluVal; prevC = cwhVal; prevW = wwhVal; delay(hold); // Pause for optional 'wait' milliseconds before resuming the loop }
The color settings in the code are quite basic, as I plan on changing them to more detail soon.
At that point, I will also slow it down, and re-upload the code here as well.
(Whew, I think that's everything!)

Hope this can be of use to someone!
Also, a big thank you to the members here in the chatbox that have assisted me in getting this project off the ground!
I couldn't have done it without them!
Andrew
vBulletin Message