Tiny 4-pixel wide font with the following characters: 0123456789ABCDEF+-%*=.:!?/\'
		public override void Run()
		{
			var tinyFont = new TinyFont();

			ISenseHatDisplay display = SenseHat.Display;

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

				if (SenseHat.Sensors.Temperature.HasValue)
				{
					int temperature = (int)Math.Round(SenseHat.Sensors.Temperature.Value);
					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();

					// 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));
				}
			}
		}
Ejemplo n.º 2
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));
				}
			}
		}