1

I'm trying to change color of the light each second, and I am using the following code.

private async void button5_Click(object sender, EventArgs e)
    {
        var command = new LightCommand();
        command.TurnOn().SetColor("BC8F8F");
        command.Brightness = 128;
        while (true)
        {
            command.Alert = Alert.Once;
            command.TransitionTime = TimeSpan.FromMilliseconds(100);
            command.TurnOn().SetColor("0054FF");
            command.Alert = Alert.Once;
            command.TurnOn().SetColor("BC8F8F");
            command.TransitionTime = TimeSpan.FromMilliseconds(100);

            var result = await client.SendCommandAsync(command);
        }
    }

My goal is changing the color alternately between 0054FF and BC8F8F, each second, but when I debug it, only the BC8F8F color appears.

What is the problem with my code?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Pearl Fall
  • 21
  • 5

1 Answers1

2

Your code basically overrides the first command. You probably need to send two of them, each containing it's own color.

D. Jurcau
  • 190
  • 6