// Function for setting lamp flicker private static void SetFlicker(bool enable) { if (enable) { ColorFlow flow = new ColorFlow(0, ColorFlowEndAction.Restore); flow.Add(new ColorFlowRGBExpression(lampColor[0], lampColor[1], lampColor[1], lampBrightness, 2000)); flow.Add(new ColorFlowRGBExpression(lampColor[0], lampColor[1], lampColor[2], lampBrightness - flickerAmount, 1000)); lamp.StartColorFlow(flow); lampFlicker = true; } else { lampFlicker = false; lamp.StopColorFlow(); } }
public static async Task StartLightFlow() { if (device.IsConnected) { Random rand = new Random(); ColorFlow flow = new ColorFlow(0, ColorFlowEndAction.Restore); flow.Add(new ColorFlowRGBExpression(27, 149, 211, 100, rand.Next(200, 450))); // color : red / brightness : 1% / duration : 500 flow.Add(new ColorFlowRGBExpression(206, 95, 26, 100, rand.Next(200, 450))); // color : green / brightness : 100% / duration : 500 flow.Add(new ColorFlowRGBExpression(31, 88, 162, 100, rand.Next(200, 450))); // color : blue / brightness : 50% / duration : 500 flow.Add(new ColorFlowRGBExpression(213, 122, 25, 100, rand.Next(200, 450))); flow.Add(new ColorFlowRGBExpression(104, 62, 139, 100, rand.Next(200, 450))); flow.Add(new ColorFlowRGBExpression(232, 178, 20, 100, rand.Next(200, 450))); flow.Add(new ColorFlowRGBExpression(163, 65, 141, 100, rand.Next(200, 450))); flow.Add(new ColorFlowRGBExpression(253, 236, 16, 100, rand.Next(200, 450))); flow.Add(new ColorFlowRGBExpression(200, 46, 129, 100, rand.Next(200, 450))); flow.Add(new ColorFlowRGBExpression(129, 178, 61, 100, rand.Next(200, 450))); await device.StartColorFlow(flow); // start } }
private static async Task Main(string[] args) { //NetworkDiscovery.PingAll(); DeviceLocator.UseAllAvailableMulticastAddresses = true; IEnumerable <Device> lights = await DeviceLocator.DiscoverAsync(); if (lights.Count() < 1) { Console.Out.WriteLine("No lights found."); return; } DeviceGroup deviceGroup = new DeviceGroup(); foreach (Device light in lights) { Console.Out.WriteLine($"Found Light: {light.Model} on {light.Hostname}"); deviceGroup.Add(light); } Console.Out.WriteLine($"Found {deviceGroup.Count} lights."); //YeelightAPI.Device device = new Device(IP); await deviceGroup.Connect(); await deviceGroup.SetRGBColor(255, 255, 255); await deviceGroup.SetBrightness(100); ConsoleKeyInfo input = new ConsoleKeyInfo(); do { input = Console.ReadKey(true); switch (input.Key) { case ConsoleKey.UpArrow: ColorFlow flow = new ColorFlow(0, ColorFlowEndAction.Restore); flow.Add(new ColorFlowRGBExpression(255, 0, 0, 1, 500)); flow.Add(new ColorFlowRGBExpression(0, 255, 0, 1, 500)); Console.Out.WriteLine("BLINK"); await deviceGroup.StartColorFlow(flow); break; case ConsoleKey.DownArrow: await deviceGroup.StopColorFlow(); Console.Out.WriteLine("STOP"); break; } Thread.Sleep(40); }while (input.Key != ConsoleKey.Escape); }