コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }