Example #1
0
        private static async Task DemoEffects(LifxClient client)
        {
            Console.WriteLine();
            Light light = (await client.ListLights(new Selector.GroupLabel("Room 1"))).FirstOrDefault();

            if (light == null)
            {
                // Find a connected light
                foreach (var l in await client.ListLights())
                {
                    if (l.IsConnected)
                    {
                        light = l;
                        break;
                    }
                }
                if (!light.IsConnected)
                {
                    Console.WriteLine("No connected lights");
                    return;
                }
            }
            Console.WriteLine("Using light: {0}", light);

            Console.WriteLine("Pulsing slowly between previously set color and green");
            await light.PulseEffect(LifxColor.Green, 1, 10);

            await Task.Delay(EFFECT_DELAY);

            /* If strobing with a single color (therefore the light alternates between the "color" parameter and "fromColor"
             * parameter which should be set to LifxColor.OffState (zero brightness) you must set the "color" parameter to a custom color
             * with a brightness value explicitly set. The default named parameters appear to leave the light in a fixed zero brightness state
             * until the end of the effect. */
            Console.WriteLine("Pulsing quickly in white");
            await light.PulseEffect(new LifxColor.White(1, 3500), 0.1, 50, fromColor : LifxColor.OffState);

            await Task.Delay(EFFECT_DELAY);

            Console.WriteLine("Breathing red alert light.");
            await light.BreatheEffect(new LifxColor.RGB(120, 0, 0), 2.5, 4, LifxColor.OffState, peak : 0.4d);

            await Task.Delay(EFFECT_DELAY);

            Console.WriteLine("\"Party breathe\", will pass through intermediate colors.");
            await light.BreatheEffect(LifxColor.Cyan, 5, 4, LifxColor.Orange, peak : 0.5d);

            await Task.Delay(EFFECT_DELAY);

            List <LightState> stateList = new List <LightState>();

            stateList.Add(new LightState(PowerState.On, LifxColor.Pink, 0.5d));
            stateList.Add(new LightState(PowerState.On, LifxColor.Pink, 1.0d));
            stateList.Add(new LightState(PowerState.On, LifxColor.DefaultWhite, 1.0d));
            stateList.Add(new LightState(PowerState.On, LifxColor.Green));
            stateList.Add(new LightState(PowerState.On, LifxColor.Blue, 1.0d));
            stateList.Add(new LightState(PowerState.On, LifxColor.Blue, 0.5d));
            LightState defaults = new LightState();

            defaults.Duration   = 3.0d;
            defaults.Brightness = 1.0d;

            // Cycle forward
            Console.WriteLine("Cycling forward through set of 6 light states.");
            for (int i = 0; i < stateList.Count(); i++)
            {
                await light.Cycle(stateList, defaults);

                await Task.Delay(4000);
            }

            await Task.Delay(1000);

            // Cycle backward
            Console.WriteLine("Cycling backward through set of 6 light states.");
            for (int i = 0; i < stateList.Count(); i++)
            {
                await light.Cycle(stateList, defaults, Direction.Backward);

                await Task.Delay(4000);
            }
        }