// 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 sensor class BME280 = new BME280Sensor(); //Initialize the sensor await BME280.Initialize(); //Create variables to store the sensor data: temperature, pressure, humidity and altitude. //Initialize them to 0. float temp = 0; float pressure = 0; float altitude = 0; float humidity = 0; //Create a constant for pressure at sea level. //This is based on your local sea level pressure (Unit: Hectopascal) const float seaLevelPressure = 1022.00f; //Read 10 samples of the data for (int i = 0; i < 10; i++) { temp = await BME280.ReadTemperature(); pressure = await BME280.ReadPreasure(); altitude = await BME280.ReadAltitude(seaLevelPressure); humidity = await BME280.ReadHumidity(); //Write the values to your debug console Debug.WriteLine("Temperature: " + temp.ToString() + " deg C"); Debug.WriteLine("Humidity: " + humidity.ToString() + " %"); Debug.WriteLine("Pressure: " + pressure.ToString() + " Pa"); Debug.WriteLine("Altitude: " + altitude.ToString() + " m"); Debug.WriteLine(""); } } 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 sensor class BME280 = new BME280Sensor(); //Initialize the sensor await BME280.Initialize(); //Create variables to store the sensor data: temperature, pressure, humidity and altitude. //Initialize them to 0. float temp = 0; float pressure = 0; float altitude = 0; float humidity = 0; //Create a constant for pressure at sea level. //This is based on your local sea level pressure (Unit: Hectopascal) const float seaLevelPressure = 1022.00f; //Read 10 samples of the data for (int i = 0; i < 10; i++) { temp = await BME280.ReadTemperature(); pressure = await BME280.ReadPreasure(); altitude = await BME280.ReadAltitude(seaLevelPressure); humidity = await BME280.ReadHumidity(); //Write the values to your debug console Debug.WriteLine("Temperature: " + temp.ToString() + " deg C"); Debug.WriteLine("Humidity: " + humidity.ToString() + " %"); Debug.WriteLine("Pressure: " + pressure.ToString() + " Pa"); Debug.WriteLine("Altitude: " + altitude.ToString() + " m"); Debug.WriteLine(""); } } 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"); /* Now that everything is initialized, create a timer so we read data every 500mS */ // int periodicTimer = new Timer(this.Timer_Tick, null, 0, 100); try { // Create a new object for our sensor class BME280 = new BME280Sensor(); //Initialize the sensor await BME280.Initialize(); //Create a new object for the color sensor class colorSensor = new Lesson_205.TCS34725(); //Initialize the sensor await colorSensor.Initialize(); //Initialize mcp3008 to get potentimeter values mcp3008.Initialize(); //Create variables to store the sensor data: temperature, pressure, humidity and altitude. //Initialize them to 0. //Read 10 samples of the data for (int i = 0; i < 12; i++) { temp = await BME280.ReadTemperature(); colorRead = await colorSensor.getClosestColor(); int lowPotReadVal = mcp3008.ReadADC(LowPotentiometerADCChannel) / 100; switch (colorRead) { case "Red": colorNum = 0; break; case "Purple": colorNum = 1; break; case "Blue": colorNum = 2; break; case "DarkSlateBlue": colorNum = 3; break; case "Green": colorNum = 4; break; case "Yellow": colorNum = 5; break; default: colorNum = 6; break; } // Let us know what was read in. Debug.WriteLine(String.Format("Read values {0}", lowPotReadVal)); //Write the values to your debug console Debug.WriteLine("Temperature: " + temp.ToString() + " deg C"); Debug.WriteLine("Color: " + colorNum.ToString() + " %"); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }