I'm doing a project on Raspberry Pi, using Windows IoT. Specifically, I'm doing a traffic light with LEDs and on the screen of my app I also drew a semaphore with ellipses. Ellipses "off" must have the lightgray color and "lit" their corresponding colors (green, yellow and red). With a Timer I am making the whole process repeat to simulate a traffic light working eternally.
The code is as follows:
public sealed partial class MainPage : Page
{
GpioPin LedVerde;
GpioPin LedAmarillo;
GpioPin LedRojo;
public MainPage()
{
this.InitializeComponent();
GpioController gpio = GpioController.GetDefault();
//configuración de los pines
LedRojo = gpio.OpenPin(23);
LedAmarillo = gpio.OpenPin(24);
LedVerde = gpio.OpenPin(25);
LedVerde.SetDriveMode(GpioPinDriveMode.Output);
LedAmarillo.SetDriveMode(GpioPinDriveMode.Output);
LedRojo.SetDriveMode(GpioPinDriveMode.Output);
LedVerde.Write(GpioPinValue.Low);
LedAmarillo.Write(GpioPinValue.Low);
LedRojo.Write(GpioPinValue.Low);
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(10);
timer.Tick += timer_Tick;
timer.Start();
}
private void timer_Tick(object sender, object e)
{
LedRojo.Write(GpioPinValue.Low);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.Green);
LedVerde.Write(GpioPinValue.High);
Task.Delay(3000).Wait();
LedVerde.Write(GpioPinValue.Low);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.LightGray);
Task.Delay(300).Wait();
LedVerde.Write(GpioPinValue.High);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.Green);
Task.Delay(300).Wait();
LedVerde.Write(GpioPinValue.Low);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.LightGray);
Task.Delay(300).Wait();
LedVerde.Write(GpioPinValue.High);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.Green);
Task.Delay(300).Wait();
LedVerde.Write(GpioPinValue.Low);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.LightGray);
Task.Delay(300).Wait();
LedVerde.Write(GpioPinValue.High);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.Green);
Task.Delay(300).Wait();
LedVerde.Write(GpioPinValue.Low);
LuzVerde.Fill = new SolidColorBrush(Windows.UI.Colors.LightGray);
LedAmarillo.Write(GpioPinValue.High);
LuzAmarilla.Fill = new SolidColorBrush(Windows.UI.Colors.Yellow);
Task.Delay(1500).Wait();
LedAmarillo.Write(GpioPinValue.Low);
LuzAmarilla.Fill = new SolidColorBrush(Windows.UI.Colors.LightGray);
LedRojo.Write(GpioPinValue.High);
LuzRoja.Fill = new SolidColorBrush(Windows.UI.Colors.Red);
}
}
The problem is that when I run the application, the LEDs change correctly, but the ellipses do not, only the red goes from lightgray to network at the end of the timer and does not turn off again.