private void cmdSet_Click(object sender, RoutedEventArgs e) { RGBData colorData = new RGBData(); colorData.Red = Convert.ToInt16(sldRed.Value); colorData.Green = Convert.ToInt16(sldGreen.Value); colorData.Blue = Convert.ToInt16(sldBlue.Value); UpdateSampleColor(colorData); }
private async void gpioPushbutton_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args) { //Only read the sensor value when the button is released if (args.Edge == GpioPinEdge.RisingEdge) { //Read the approximate color from the sensor _colorSensor.LedState = TCS34725.eLedState.On; await System.Threading.Tasks.Task.Delay(1000); RGBData colorData = await _colorSensor.GetRgbData(); _colorSensor.LedState = TCS34725.eLedState.Off; UpdateSampleColor(colorData); } }
private void ResetLEDsAndTimers(RGBData color) { _timerRed.Stop(); _timerGreen.Stop(); _timerBlue.Stop(); _pinValRed = SetGpioPinState(_gpioRedLED, GpioPinValue.Low); _pinValGreen = SetGpioPinState(_gpioGreenLED, GpioPinValue.Low); _pinValBlue = SetGpioPinState(_gpioBlueLED, GpioPinValue.Low); _timerRed.Interval = LED_OFF_DURATION_MSEC; _timerGreen.Interval = LED_OFF_DURATION_MSEC; _timerBlue.Interval = LED_OFF_DURATION_MSEC; _timerRed.Start(); _timerGreen.Start(); _timerBlue.Start(); }
// Updates the sample square in headed mode private async void UpdateSampleColor(RGBData color) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { rectSample.Fill = new SolidColorBrush(Color.FromArgb(255, (byte)color.Red, (byte)color.Green, (byte)color.Blue)); sldRed.Value = color.Red; sldGreen.Value = color.Green; sldBlue.Value = color.Blue; if (_isInitialized) { _redLEDDurationMsec = GetLEDDurationForValue(color.Red); _greenLEDDurationMsec = GetLEDDurationForValue(color.Green); _blueLEDDurationMsec = GetLEDDurationForValue(color.Blue); ResetLEDsAndTimers(color); } }); }
//Method to read the RGB data public async Task <RGBData> GetRgbData() { //Create an object to store the raw color data RGBData rgbData = new RGBData(); //First get the raw color data ColorData colorData = await GetRawData(); //Check if clear data is received if (colorData.Clear > 0) { //Find the RGB values from the raw data using the clear data as reference rgbData.Red = (colorData.Red * 255 / colorData.Clear); rgbData.Blue = (colorData.Blue * 255 / colorData.Clear); rgbData.Green = (colorData.Green * 255 / colorData.Clear); } //Write the RGB values to the debug console Debug.WriteLine("RGB Data - red: {0}, green: {1}, blue: {2}", rgbData.Red, rgbData.Green, rgbData.Blue); //Return the data return(rgbData); }
//Method to read the RGB data public async Task<RGBData> GetRgbData() { //Create an object to store the raw color data RGBData rgbData = new RGBData(); //First get the raw color data ColorData colorData = await GetRawData(); //Check if clear data is received if (colorData.Clear > 0) { //Find the RGB values from the raw data using the clear data as reference rgbData.Red = (colorData.Red * 255 / colorData.Clear); rgbData.Blue = (colorData.Blue * 255 / colorData.Clear); rgbData.Green = (colorData.Green * 255 / colorData.Clear); } //Write the RGB values to the debug console Debug.WriteLine("RGB Data - red: {0}, green: {1}, blue: {2}", rgbData.Red, rgbData.Green, rgbData.Blue); //Return the data return rgbData; }