Beispiel #1
0
        public override void Run()
        {
            // The initial position of the pixel.
            int x = 3;
            int y = 3;

            SenseHat.Display.Clear();

            while (true)
            {
                if (SenseHat.Joystick.Update())                           // Has any of the buttons on the joystick changed?
                {
                    UpdatePosition(ref x, ref y);                         // Move the pixel.

                    SenseHat.Display.Clear();                             // Clear the screen.

                    SenseHat.Display.Screen[x, y] = _colors[_colorIndex]; // Draw the pixel.

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

                    SetScreenText?.Invoke($"{x}, {y}");                   // Update the MainPage (if it's utilized; i.e. not null).
                }

                // Take a short nap.
                Sleep(TimeSpan.FromMilliseconds(2));
            }
        }
Beispiel #2
0
        public override void Run()
        {
            DateTime dt;
            int      hours;
            int      minutes;
            int      seconds;

            SenseHat.Display.Clear();

            while (true)
            {
                SenseHat.Display.Clear();
                SenseHat.Display.Screen[0, 0] = _colors[2];// find corner = top left

                dt      = DateTime.Now;
                hours   = dt.Hour;
                minutes = dt.Minute;
                seconds = dt.Second;

                DrawBinary(0, hours);
                DrawBinary(3, minutes);
                DrawBinary(6, seconds);

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

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

                // Take a short nap.
                Sleep(TimeSpan.FromMilliseconds(200));
            }
        }
        public override void Run()
        {
            var    tinyFont = new TinyFont();
            Cpu    cpu      = new Cpu();
            double temp_calibrated;

            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);
                    double?cpu_temp         = cpu.GetTemperature();
                    if (cpu_temp != null)
                    {
                        temp_calibrated = temperatureValue - (((double)cpu_temp - temperatureValue) / 0.79);
                    }
                    else
                    {
                        temp_calibrated = temperatureValue;
                    }

                    int temperature = (int)Math.Round((double)temp_calibrated);

                    string text = temperature.ToString();

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

                    display.Clear();
                    tinyFont.Write(display, text, Color.Blue);
                    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));
                }
            }
        }
        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));
            }
        }