コード例 #1
0
        public override void Run()
        {
            var tinyFont = new TinyFont();

            ISenseHatDisplay display = SenseHat.Display;

            TemperatureUnit unit = TemperatureUnit.Celcius;  // The wanted temperature unit.

            string unitText = GetUnitText(unit);             // Get the unit as a string.

            while (true)
            {
                SenseHat.Sensors.HumiditySensor.Update();

                if (SenseHat.Sensors.Temperature.HasValue)
                {
                    double temperatureValue = ConvertTemperatureValue(unit, SenseHat.Sensors.Temperature.Value);

                    int    temperature = (int)Math.Round(temperatureValue);
                    string text        = temperature.ToString();

                    if (text.Length > 2)
                    {
                        // Too long to fit the display!
                        text = "**";
                    }

                    display.Clear();
                    tinyFont.Write(display, text, Colors.White);
                    display.Update();

                    SetScreenText?.Invoke($"{temperatureValue:0.0} {unitText}");                     // Update the MainPage (if it's utilized; i.e. not null).

                    // Sleep quite some time; the temperature usually change quite slowly...
                    Sleep(TimeSpan.FromSeconds(5));
                }
                else
                {
                    // Rapid update until there is a temperature reading.
                    Sleep(TimeSpan.FromSeconds(0.5));
                }
            }
        }
コード例 #2
0
        public override void Run()
        {
            while (true)
            {
                SenseHat.Display.Clear();
                SenseHat.Display.Screen[0, 0] = _activeBitColor; // Place a dot to mark the top left corner.

                DateTime now = DateTime.Now;

                DrawBinary(0, now.Hour);
                DrawBinary(3, now.Minute);
                DrawBinary(6, now.Second);

                SenseHat.Display.Update();                           // Update the physical display.

                SetScreenText?.Invoke(now.ToString("HH':'mm':'ss")); // Update the MainPage (if it's utilized; i.e. not null).

                // Take a short nap.
                Sleep(TimeSpan.FromMilliseconds(200));
            }
        }