/// <summary> /// Sets the color of a led. /// </summary> /// <param name="ledNumber">Led number (zero based index).</param> /// <param name="color">The color.</param> public void SetColor(int ledNumber, RgbColor color) { // Send data frame prefix (32x "0") SendByte(0x00); SendByte(0x00); SendByte(0x00); SendByte(0x00); // Send color data for each one of the leds for (int i = 0; i < ledColors.Count; i++) { if (i == ledNumber) { ledColors [i].Red = color.Red; ledColors [i].Green = color.Green; ledColors [i].Blue = color.Blue; } // Start by sending a byte with the format "1 1 /B7 /B6 /G7 /G6 /R7 /R6" byte prefix = Convert.ToByte("11000000", 2); if ((color.Blue & 0x80) == 0) prefix |= Convert.ToByte("00100000", 2); if ((color.Blue & 0x40) == 0) prefix |= Convert.ToByte("00010000", 2); if ((color.Green & 0x80) == 0) prefix |= Convert.ToByte("00001000", 2); if ((color.Green & 0x40) == 0) prefix |= Convert.ToByte("00000100", 2); if ((color.Red & 0x80) == 0) prefix |= Convert.ToByte("00000010", 2); if ((color.Red & 0x40) == 0) prefix |= Convert.ToByte("00000001", 2); SendByte(prefix); // Now must send the 3 colors SendByte(ledColors [i].Blue); SendByte(ledColors [i].Green); SendByte(ledColors [i].Red); } // Terminate data frame (32x "0") SendByte(0x00); SendByte(0x00); SendByte(0x00); SendByte(0x00); }
/// <summary> /// Sets the color of a led. /// </summary> /// <param name="ledNumber">Led number (zero based index).</param> /// <param name="h">Hue.</param> /// <param name="s">Saturation.</param> /// <param name="v">Value.</param> public void SetColorHsv(int ledNumber, double h, double s, double v) { RgbColor color = HsvToRgb(h, s, v); SetColorRgb(ledNumber, color.Red, color.Green, color.Blue); }