private void PeriodicRefreshTask(int intervalInMS, CancellationToken cancellationToken) { var rgbDisplay = GrovePiRgbLcdDisplay.BuildRgbLcdDisplayImpl(); rgbDisplay.SetBacklightRgb(10, 10, 10); Task.Run(async() => { while (!cancellationToken.IsCancellationRequested) { try { foreach (var sensor in sensors.Where(sen => sen.RgbDisplay)) { rgbDisplay.SetText(sensor.Name, sensor.Value.ToString("0.0") + " " + sensor.Unit); if (!cancellationToken.IsCancellationRequested) { await Task.Delay(intervalInMS, cancellationToken); } } } catch (TaskCanceledException) { Console.WriteLine("IotProject PeriodicRefreshTask has been cancelled"); } catch (Exception ex) { Console.WriteLine("IotProject error: " + ex.Message + " - " + ex.StackTrace); } } }); }
public static void WriteLCD(string message) { var rgbDisplay = GrovePiRgbLcdDisplay.BuildRgbLcdDisplayImpl(); rgbDisplay.SetText(message); }