private static void Main() { _sensor = new BME280(Hardware.SocketOne, BME280.I2CAddresses.Address0) { TemperatureUnit = TemperatureUnits.Fahrenheit, PressureCompensation = PressureCompensationModes.SeaLevelCompensated }; _sensor.SetRecommendedMode(BME280.RecommendedModes.WeatherMonitoring); while (true) { Debug.WriteLine("------Reading individual values-------"); Debug.WriteLine($"Pressure.......: {_sensor.ReadPressure():F1} hPa"); Debug.WriteLine($"Temperature....: {_sensor.ReadTemperature():F2} °F"); Debug.WriteLine($"Humidity.......: {_sensor.ReadHumidity():F2} %RH"); Debug.WriteLine($"Altitude.......: {_sensor.ReadAltitude():F0} meters\n"); _sensor.ReadSensor(out Single pressure, out Single temperature, out Single humidity, out Single altitude); Debug.WriteLine("------Using the ReadSensor Method-------"); Debug.WriteLine($"Pressure.......: {pressure:F1} hPa"); Debug.WriteLine($"Temperature....: {temperature:F2} °F"); Debug.WriteLine($"Humidity.......: {humidity:F2} %RH"); Debug.WriteLine($"Altitude.......: {altitude:F0} meters\n"); Thread.Sleep(5000); } }
private void TimerCallback(object state) { var temp = bme280.ReadTemperature(); var press = bme280.ReadPreasure() / 100; var humidity = bme280.ReadHumidity(); var alt = bme280.ReadAltitude(1013); // 1013hPa = pressure at 0m Debug.WriteLine("Temp:{0:F2}℃ Humidity:{1:F2}% Press:{2:F2}hPa Alt:{3:F0}m", temp, humidity, press, alt); var task = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { tempValue.Text = temp.ToString("F2") + "℃"; humValue.Text = humidity.ToString("F2") + "%"; pressValue.Text = press.ToString("F2") + "hPa"; }); }