/// <summary> /// http://colormine.org/color-converter /// </summary> public void TestC() { //int v1 = 0, v2 = 0; // the new vertex and the previous one for (var hue = 0; hue < 360; hue += 2) { var light = 40; for (var sat = 40; sat <= 80; sat += 10) { var color = RGBHelper.HsvToRgb(hue, sat, light); Console.WriteLine(" hue:{0:000} sat:{1:000}, light:{2:000}, color:{3:000}", hue, sat, light, color); this.AddRGBSequence(true, 6, this.MaxLed, color); this.Show(); Thread.Sleep(2); } if (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Q) { break; } } } }
public static void TrigonometrieOneColorDemo(APA102LEDStrip ledStrip) { var wait = GetWaitTimeUnit(ledStrip); if (ledStrip.MaxLed <= 10) { wait *= 3; } var maxLed = ledStrip.MaxLed; var quit = false; ledStrip.Brightness = 16; ledStrip.AllOff(); Console.Clear(); ConsoleEx.TitleBar(0, "Trigonometrie Demo"); ConsoleEx.WriteMenu(-1, 2, "Q)uit"); ConsoleEx.WriteMenu(-1, 3, ""); var _4Sin_div_PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(radianV) / (1 * Math.PI), colorMinValue: 64); var _4Sin3_div_3PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(3 * radianV) / (3 * Math.PI), colorMinValue: 64); var _4Sin5_div_5PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(5 * radianV) / (5 * Math.PI), colorMinValue: 32); var _4Sin7_div_7PI = RGBHelper.GenerateTrigonometricValues(maxLed, Math.PI, radianV => 4 * Math.Sin(7 * radianV) / (7 * Math.PI), colorMinValue: 32); // Green var greenColorVariation0 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin_div_PI, null); var greenColorVariation1 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin3_div_3PI, null); var greenColorVariation2 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin5_div_5PI, null); var greenColorVariation3 = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin7_div_7PI, null); while (!quit) { if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation0, "4*Math.Sin(radianV) /(1*Math.PI)")) { break; } if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation1, "4*Math.Sin(3*radianV)/(3*Math.PI)")) { break; } if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation2, "4*Math.Sin(5*radianV)/(5*Math.PI)")) { break; } if (!PlayTrigonometrieVariation(ledStrip, wait, greenColorVariation3, "4*Math.Sin(7*radianV)/(7*Math.PI)")) { break; } if (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Q) { break; } } } ledStrip.AllOff(); }
public static void LineDemo(APA102LEDStrip ledStrip) { int wait = ledStrip.MaxLed <= 10 ? 55 : 0; var quit = false; ledStrip.AllOff(); Console.Clear(); ConsoleEx.TitleBar(0, "Line Demo"); ConsoleEx.WriteMenu(-1, 2, "Q)uit"); ConsoleEx.WriteMenu(-1, 3, ""); while (!quit) { var j = 0; for (var i = 0; i < ledStrip.MaxLed; i++) { // Remark: there should be a faster way to draw the line, by first setting all the led // to black and only resetting the one in color. Once we light up all the led, we would // turn them all off and re start... Todo, totry. var bkColor = RGBHelper.Wheel(((i * 256 / ledStrip.MaxLed) + j)); ledStrip.AddRGBSequence(true, 2, i + 1, bkColor); if (++j >= 256) { j = 0; } while (!ledStrip.IsFull) { ledStrip.AddRGBSequence(false, 2, Color.Black); } ledStrip.Show().Wait(wait); Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor))); if (Console.KeyAvailable) { while (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { quit = true; break; } } } } ledStrip.Wait(wait * 3).AllOff(); } ledStrip.AllOff(); }
public static void PerformanceTest(APA102LEDStrip ledStrip) { ledStrip.Brightness = 16; ledStrip.AllOff(); Console.Clear(); Console.WriteLine("Running test..."); var bkColor = Color.Red; var sw = Stopwatch.StartNew(); var testCount = 1000; var wheelIndex = 0; // This loop set the strip 500 x 2 == 1000 times for (var t = 0; t < (testCount / 2); t++) { bkColor = RGBHelper.Wheel(wheelIndex); wheelIndex += 2; if (wheelIndex >= 256) { wheelIndex = 0; } // Light up in red the 60 led strips ledStrip.Reset(); for (var l = 0; l < ledStrip.MaxLed; l++) { ledStrip.AddRGBSequence(false, 7, bkColor); } ledStrip.Show(); // Turn it off the 60 led strips ledStrip.Reset(); for (var l = 0; l < ledStrip.MaxLed; l++) { ledStrip.AddRGBSequence(false, 7, Color.Black); } ledStrip.Show(); } sw.Stop(); var bytePerSeconds = ledStrip.MaxLed * 4 * testCount / (sw.ElapsedMilliseconds / 1000); Console.WriteLine("test Duration:{0}, BytePerSecond:{1}, NumberOfLedTurnOnOrOff:{2}", sw.ElapsedMilliseconds, bytePerSeconds, ledStrip.MaxLed * testCount ); var k = Console.ReadKey(true).Key; ledStrip.AllOff(); k = Console.ReadKey(true).Key; }
public static Color ToBrighter(Color color, int percent = 10) { double hue; double saturation; double value; RGBHelper.ColorToHSV(color, out hue, out saturation, out value); saturation = saturation * (1 + (percent / 100.0)); value = value * (1 + (percent / 100.0)); return(RGBHelper.HsvToRgb(hue, saturation, value)); }
public static void LineDemo(APA102LEDStrip ledStripe) { int wait = 20; var quit = false; ledStripe.AllOff(); Console.Clear(); ConsoleEx.WriteMenu(-1, 4, "Q)uit"); while (!quit) { var j = 0; for (var i = 0; i < ledStripe.MaxLed; i++) { var bkColor = RGBHelper.Wheel(((i * 256 / ledStripe.MaxLed) + j)); ledStripe.AddRGBSequence(true, 2, i + 1, bkColor); if (++j >= 256) { j = 0; } while (!ledStripe.IsFull) { ledStripe.AddRGBSequence(false, 2, Color.Black); } ledStripe.Show().Wait(wait); Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor))); if (Console.KeyAvailable) { while (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { quit = true; break; } } } } ledStripe.Wait(wait * 3).AllOff(); } ledStripe.AllOff(); }
public static void RainbowDemo2(APA102LEDStrip ledStrip, int jStep) { Console.Clear(); ConsoleEx.TitleBar(0, "Rainbow Demo"); ConsoleEx.WriteMenu(-1, 2, "Q)uit"); ConsoleEx.WriteMenu(-1, 3, ""); int brigthness = 6; int wait = GetWaitTimeUnit(ledStrip) / 2; var quit = false; ledStrip.AllOff(); while (!quit) { for (var j = 0; j < 256; j += jStep) { ConsoleEx.Gotoxy(0, 4); ledStrip.Reset(); for (var i = 0; i < ledStrip.MaxLed; i++) { ledStrip.AddRGBSequence(false, brigthness, RGBHelper.Wheel((i * 256 / ledStrip.MaxLed) + j)); } for (var i = 0; i < ledStrip.MaxLed; i++) { var wheelIndex = (i * 256 / ledStrip.MaxLed) + j; var bkColor = ledStrip.LedColors[i]; Console.WriteLine(String.Format("Color:{0}, Wheel:{1}, rgb:{2}", bkColor.Name, wheelIndex.ToString("000"), APA102LEDStrip.ToDecValue(bkColor))); } ledStrip.Show().Wait(wait); if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { quit = true; break; } } } } ledStrip.AllOff(); }
private BubbleColor[] InitRandomBubbleColors() { Random rnd = new Random(); BubbleColor[] bubbleColors = new BubbleColor[nusbioPixel.Count]; for (int i = 0; i < nusbioPixel.Count; i++) { var color = RGBHelper.Wheel((i * 256 / nusbioPixel.Count) + 4); bubbleColors[i] = new BubbleColor(); bubbleColors[i].color = color; // r = color.R; bubbleColors[i].originalPosition = i; // = (int)(0.299 * bubbleColors[i].r + 0.587 * bubbleColors[i].g + 0.144 * bubbleColors[i].b); } bubbleColors = bubbleColors.OrderBy(a => Guid.NewGuid()).ToArray <BubbleColor>(); for (int i = 0; i < nusbioPixel.Count; i++) { nusbioPixel.SetPixel(i, bubbleColors[i].color.R, bubbleColors[i].color.G, bubbleColors[i].color.B); } nusbioPixel.SetBrightness(30); nusbioPixel.Show(); return(bubbleColors); }
public static void MultiShades(APA102LEDStrip ledStrip) { int wait = 0; var quit = false; ledStrip.AllOff(); while (!quit) { for (var j = 0; j < 256; j++) { Console.Clear(); ledStrip.Reset(); for (var i = 0; i < ledStrip.MaxLed; i++) { ledStrip.AddRGBSequence(false, 10, RGBHelper.Wheel(((i + j)))); } foreach (var bkColor in ledStrip.LedColors) { Console.WriteLine(String.Format("Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor))); } ledStrip.Show().Wait(wait); if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { quit = true; break; } } } } ledStrip.AllOff(); }
public static void TrigonometrieMultiColorEvolutionDemo(APA102LEDStrip ledStrip) { APA102LEDStrip.CombineSPIDataAndClockOnSameCycle = true; var wait = GetWaitTimeUnit(ledStrip); if (ledStrip.MaxLed <= 10) { wait *= 3; } var maxLed = ledStrip.MaxLed; var quit = false; ledStrip.Brightness = 16; ledStrip.AllOff(); Console.Clear(); ConsoleEx.TitleBar(0, "Trigonometrie Demo"); ConsoleEx.WriteMenu(-1, 2, "Q)uit"); ConsoleEx.WriteMenu(-1, 3, ""); var trigoCircleMax = Math.PI / 2; var amplitude = 4; var amplitudeStep = 0.1; var amplitudeFactor = amplitudeStep; amplitudeFactor = 1; var minPhaseOffSet = 0.0; var maxPhaseOffSet = Math.PI; var phaseOffSetStep = maxPhaseOffSet / 100; var phaseOffSet = 0.0; var _4Sin3_div_3PI = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax, radianV => (amplitudeFactor * amplitude) * Math.Sin((3 * radianV)) / (3 * Math.PI), colorMinValue: 128, diplayData: true); var _4Sin5_div_5PI_Phase2 = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax, radianV => (amplitudeFactor * amplitude) * Math.Sin((5 * radianV)) / (5 * Math.PI), colorMinValue: 128, diplayData: true); var _4Sin7_div_7PI_Phase3 = RGBHelper.GenerateTrigonometricValues(maxLed, trigoCircleMax, radianV => (amplitudeFactor * amplitude) * Math.Sin((7 * radianV)) / (7 * Math.PI), colorMinValue: 128, diplayData: true); List <System.Drawing.Color> colorVariation = null; int loopIndex = 0; while (!quit) { Console.WriteLine("amplitudeFactor:{0}, phaseOffSet:{1}", amplitudeFactor, phaseOffSet); switch (loopIndex % 3) { case 0: colorVariation = RGBHelper.GenerateListOfColor(maxLed, _4Sin3_div_3PI, _4Sin5_div_5PI_Phase2, null); break; case 1: colorVariation = RGBHelper.GenerateListOfColor(maxLed, _4Sin3_div_3PI, null, _4Sin5_div_5PI_Phase2); break; case 2: colorVariation = RGBHelper.GenerateListOfColor(maxLed, null, _4Sin3_div_3PI, _4Sin5_div_5PI_Phase2); break; } //loopIndex += 1; if (!PlayTrigonometrieVariation(ledStrip, wait, colorVariation, "Experiment", 1)) { break; } //amplitudeFactor += amplitudeStep; if (amplitudeFactor > 3) { amplitudeFactor = amplitudeStep; } //phaseOffSet = phaseOffSet + phaseOffSetStep; //if (phaseOffSet > maxPhaseOffSet) // phaseOffSet = minPhaseOffSet; if (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Q) { break; } } } ledStrip.AllOff(); }
public APA102LEDStrip AddHSV(double h, double S, double V) { this.AddRGB(RGBHelper.HsvToRgb(h, S, V)); return(this); }
public APA102LEDStrip AddHSV(double hue, double saturation, double lightness, int brightness = -1) { return(this.AddRGB(RGBHelper.HsvToRgb(hue, saturation, lightness), brightness)); }
public static void RainbowDemo(APA102LEDStrip ledStrip0, int jStep, APA102LEDStrip ledStrip1, bool inSync) { Console.Clear(); ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 6, "Q)uit"); int wait = 13; var quit = false; var maxStep = 256; var brightness = 16; ledStrip0.AllOff(); ledStrip1.AllOff(); while (!quit) { var j2 = maxStep; for (var j = 0; j < maxStep; j += jStep) { if (inSync) // If in sync both led show the same color else show opposite color { j2 = j; } ledStrip0.Reset(); ledStrip1.Reset(); for (var i = 0; i < ledStrip0.MaxLed; i++) { ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j))); } for (var i = 0; i < ledStrip1.MaxLed; i++) { ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2))); } foreach (var bkColor in ledStrip0.LedColors) { ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3} ", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j), ConsoleColor.DarkCyan); } foreach (var bkColor in ledStrip1.LedColors) { ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}, WheelIndex:{3}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor), j2), ConsoleColor.DarkCyan); } ledStrip0.Show(); ledStrip1.Show().Wait(wait); if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { quit = true; break; } } j2--; } } ledStrip0.AllOff(); ledStrip1.AllOff(); }
public static void ComboWith6LedPanel(Nusbio nusbio, APA102LEDStrip ledStrip0, APA102LEDStrip ledStrip1 = null) { Console.Clear(); ConsoleEx.TitleBar(0, "Rainbow Demo", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 6, "Q)uit"); int wait = 50; var quit = false; var maxStep = 256; var brightness = 5; int jStep = 8; ledStrip0.AllOff(); ledStrip1.AllOff(); var ledIndex = -1; var maxLedIndex = 4; var ledIndexTimeOut = new TimeOut(wait * 50); while (!quit) { var j2 = maxStep; for (var j = 0; j < maxStep; j += jStep) { ledStrip0.Reset(); ledStrip1.Reset(); for (var i = 0; i < ledStrip0.MaxLed; i++) { ledStrip0.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j))); } for (var i = 0; i < ledStrip1.MaxLed; i++) { ledStrip1.AddRGBSequence(false, brightness, RGBHelper.Wheel(((i * maxStep / ledStrip0.MaxLed) + j2))); } foreach (var bkColor in ledStrip0.LedColors) { ConsoleEx.WriteLine(1, 2, String.Format("Strip 0 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan); } foreach (var bkColor in ledStrip1.LedColors) { ConsoleEx.WriteLine(1, 3, String.Format("Strip 1 - Color:{0}, Html:{1}, Dec:{2}", bkColor.Name, APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan); } j2 -= jStep; if (j2 < 0) { j2 = maxStep; } ledStrip0.Show(); ledStrip1.Show().Wait(wait); /* * // Turn on and off led connected to gpio 0,1,2,3 * if (ledIndexTimeOut.IsTimeOut()) * { * if (ledIndex != -1) * nusbio[ledIndex].Low(); * ledIndex++; * if (ledIndex == maxLedIndex) * ledIndex = 0; * nusbio[ledIndex].High(); * } */ if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { quit = true; break; } } } } ledStrip0.AllOff(); ledStrip1.AllOff(); }