Currently I'm working on a DMX Library for C# .NET. At the moment i'm stuck at creating a color transition based on a "start color" and an "end color".
The function takes 3 arguments, first is the DMXController object (basically an extended SerialPort), second is the startColor and third is endColor.
The whole trahsition will be handled in a separate thread, so the application won't hang.
The DMX Client is just a RGB LED controller so it accepts literally RGB values (e.g. Red = 255, 0, 0)
I've seen some examples with fixed colors but for this project any color can be used.
If I'm correct the maximum number of steps will be 255 steps.
What's the most efficient way to get this done? Every step in the cycle will be send to the DMXController so it must be some kind of for-next or while loop and every step will be send.
Here's my code so far:
public static void FadeColor(DMXController controller, Color startColor, Color endColor)
{
Color currentColor = startColor;
Thread fadeColorThread = new Thread(delegate()
{
// Start For-Next / While loop
// Update currentColor with new RGB values
controller.SetChannel(1, currentColor.R);
controller.SetChannel(2, currentColor.G);
controller.SetChannel(3, currentColor.B);
controller.Update();
// If neccesary a delay like Thread.Sleep(5);
// End For-Next / While loop
});
fadeColorThread.Name = "DMX Color Transition Thread";
fadeColorThread.Start();
}
If it's faster to extract r, g, and b values from the color objects before starting the transition I'll implement that.