private async Task <LightData> ReadLightData() { LightData ld = null; try { if (colorSensor == null) { colorSensor = new TCS34725(); await colorSensor.Initialize(); } //Read the approximate color from the sensor string colorRead = await colorSensor.getClosestColor(); //Output the colr name to the speaker await Speak(" The current color is: " + colorRead); RgbData rgb = await colorSensor.getRgbData(); float lux = TCS34725.getLuxSimple(rgb); ld = new LightData(); ld.Created = DateTime.Now; ld.rgbData = rgb; ld.Lux = lux; ld.ColorTempinK = TCS34725.calculateColorTemperature(rgb); Debug.WriteLine("Current lux: " + lux); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(ld); }
private void LoggerTimer_Tick(object sender, object e) { if (pinValue == GpioPinValue.High) { pinValue = GpioPinValue.Low; pin.Write(pinValue); ReadWeatherData().ContinueWith((t) => { WeatherData wd = t.Result; AdafruitIO io = new AdafruitIO(); io.sendData(wd); Debug.WriteLine(wd.Created); //Write the values to your debug console Debug.WriteLine("Created: " + wd.Created + " ft"); txtTime.Text = "Created: " + wd.Created + " ft"; Debug.WriteLine("Temperature: " + wd.TemperatureinF + " deg F"); txtTemp.Text = "Temperature: " + wd.TemperatureinF + " deg F"; Debug.WriteLine("Pressure: " + wd.Pressureinmb + " mb"); txtPressure.Text = "Pressure: " + wd.Pressureinmb + " mb"; // string json = JsonConvert.SerializeObject(wd); lcd.gotoxy(0, 1); lcd.prints("Temperature:" + Math.Round(wd.TemperatureinF, 2)); lcd.gotoxy(0, 2); lcd.prints("Pressure: " + Math.Round(wd.Pressureinmb, 2)); Debug.WriteLine(""); }, TaskScheduler.FromCurrentSynchronizationContext()); ReadLightData().ContinueWith((t) => { LightData ld = t.Result; //AdafruitIO io = new AdafruitIO(); //io.sendData(ld); Debug.WriteLine("Lux: " + ld.Lux); Debug.WriteLine("Color Temp:" + ld.ColorTempinK + " K"); // string json = JsonConvert.SerializeObject(wd); lcd.gotoxy(0, 3); lcd.prints("Lux:" + Math.Round(ld.Lux, 2)); }, TaskScheduler.FromCurrentSynchronizationContext()); pinValue = GpioPinValue.High; pin.Write(pinValue); } else { pinValue = GpioPinValue.High; pin.Write(pinValue); } }
private async Task<LightData> ReadLightData() { LightData ld = null; try { if (colorSensor == null) { colorSensor = new TCS34725(); await colorSensor.Initialize(); } //Read the approximate color from the sensor string colorRead = await colorSensor.getClosestColor(); //Output the colr name to the speaker await Speak(" The current color is: " + colorRead); RgbData rgb = await colorSensor.getRgbData(); float lux = TCS34725.getLuxSimple(rgb); ld = new LightData(); ld.Created = DateTime.Now; ld.rgbData = rgb; ld.Lux = lux; ld.ColorTempinK = TCS34725.calculateColorTemperature(rgb); Debug.WriteLine("Current lux: " + lux); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return ld; }