Example #1
0
        //This method will be called by the application framework when the page is first loaded
        protected override async void OnNavigatedTo(NavigationEventArgs navArgs)
        {
            Debug.WriteLine("MainPage::OnNavigatedTo");

            MakePinWebAPICall();

            try
            {
                //Create a new object for our barometric sensor class
                BMP280 = new BMP280();
                //Initialize the sensor
                await BMP280.Initialize();

                //Create variables to store the sensor data: temperature, pressure and altitude. 
                //Initialize them to 0.
                float temp = 0;
                float pressure = 0;
                float altitude = 0;

                //Create a constant for pressure at sea level. 
                //This is based on your local sea level pressure (Unit: Hectopascal)
                const float seaLevelPressure = 1013.25f;

                //Read 10 samples of the data
                //for(int i = 0; i < 100; i++)
                while (true)
                {
                    temp = await BMP280.ReadTemperature();
                    pressure = await BMP280.ReadPreasure(); 
                    altitude = await BMP280.ReadAltitude(seaLevelPressure);

                    //Write the values to your debug console
                    Debug.WriteLine("Temperature: " + temp.ToString() + " deg C");
                    Debug.WriteLine("Temperature: " + ConvertTemp.ConvertCelsiusToFahrenheit(temp) + " deg F");
                    Debug.WriteLine("Pressure: " + pressure.ToString() + " Pa");
                    Debug.WriteLine("Altitude: " + altitude.ToString() + " m");
                    Debug.WriteLine("Sleeping for a bit...");
                    System.Threading.Tasks.Task.Delay(3000).Wait();


                }              
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
        //This method will be called by the application framework when the page is first loaded
        protected override async void OnNavigatedTo(NavigationEventArgs navArgs)
        {
            Debug.WriteLine("MainPage::OnNavigatedTo");

            MakePinWebAPICall();

            try
            {
                //Create a new object for our barometric sensor class
                BMP280 = new BMP280();
                //Initialize the sensor
                await BMP280.Initialize();

                //Create variables to store the sensor data: temperature, pressure and altitude.
                //Initialize them to 0.
                float temp     = 0;
                float pressure = 0;
                float altitude = 0;

                //Create a constant for pressure at sea level.
                //This is based on your local sea level pressure (Unit: Hectopascal)
                const float seaLevelPressure = 1013.25f;

                //Read 10 samples of the data
                for (int i = 0; i < 10; i++)
                {
                    temp = await BMP280.ReadTemperature();

                    pressure = await BMP280.ReadPreasure();

                    altitude = await BMP280.ReadAltitude(seaLevelPressure);

                    //Write the values to your debug console
                    Debug.WriteLine("Temperature: " + temp.ToString() + " deg C");
                    Debug.WriteLine("Pressure: " + pressure.ToString() + " Pa");
                    Debug.WriteLine("Altitude: " + altitude.ToString() + " m");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }