/// <summary> /// Reads the RGB color. /// </summary> /// <returns>The RGB color.</returns> public RGBColor ReadRGB() { RGBColor rgbColor = null; if (uartMode == UARTMode.Mode4) { byte[] rawBytes = ReadBytes(6); var r = GetUInt16(rawBytes, 0); var g = GetUInt16(rawBytes, 2); var b = GetUInt16(rawBytes, 4); rgbColor = new RGBColor(r, g, b); } return(rgbColor); }
/// <summary> /// Reads the sensor value as a string. /// </summary> /// <returns> /// The value as a string /// </returns> public override string ReadAsString() { RGBColor color = ReadRGBColor(); return("Red:" + color.Red + " green:" + color.Green + " blue:" + color.Blue); }
/// <summary> /// Reads the RGB color. /// </summary> /// <returns>The RGB color.</returns> public RGBColor ReadRGB() { RGBColor rgbColor = null; if (uartMode == UARTMode.Mode4) { byte[] rawBytes = ReadBytes(6); rgbColor = new RGBColor(rawBytes[0], rawBytes[2], rawBytes[4]); } return rgbColor; }
/* * Method to retrieve the colors of the facelets, * you're welcome to play with it! * Most likely you'll have to find your own values :) */ public static char getColorValue(RGBColor color) { char colorvalue; //if (color.Red > (byte)60) { if (color.Red >= (byte)50) { //if (color.Blue >= (byte)90 || (color.Red >= (byte)160 && color.Blue <= (byte)20)) if (color.Blue >= (byte)90 || (color.Red >= (byte)160)) colorvalue = 'W'; // "white"; else if (color.Green > (byte)70) { colorvalue = 'Y'; // "yellow"; } else { //if ((float)color.Green/(float)color.Red >= .47 || color.Red >= (byte)75) if (color.Red > (byte)70 || (float)color.Green/(float)color.Red > .6 ) colorvalue = 'O'; // "orange"; else colorvalue = 'R'; // "red"; } } else { if (color.Green >= (byte)240) colorvalue = 'Y'; // "yellow"; else if (color.Blue > color.Green) { if (color.Green >= 30) colorvalue = 'B'; // "blue"; else colorvalue = 'Y'; // "yellow"; } else if (color.Green >= (byte)30) { //if ((float)color.Blue / (float)color.Green >= .34) if (color.Green >= (byte)65) colorvalue = 'G'; // "green"; else if ((int)color.Green + (int)color.Blue + (int)color.Red <= (int)300) colorvalue = 'B'; // "blue"; else colorvalue = 'W'; // "white"; } else colorvalue = 'R'; // "red"; } return colorvalue; }
public static RGBColor[] CountFacelets(Motor a, EV3ColorSensor sensor) { RGBColor[] colors = new RGBColor[8]; a.ResetTacho(); for (int count = 0; count < 8;) if (count == a.GetTachoCount () / 45 % 8) colors [count++] = sensor.ReadRGB (); return colors; }
private string ScanColor() { WaitForSensorReady(); RGBColor rgbColor = colorSensor.ReadRGB(); int max = Math.Max(Math.Max(rgbColor.Red, rgbColor.Green), rgbColor.Blue); if (max > 255) // Normalize to max 255 { rgbColor = new RGBColor( (UInt16)((int)rgbColor.Red * 255 / max), (UInt16)((int)rgbColor.Green * 255 / max), (UInt16)((int)rgbColor.Blue * 255 / max)); } Color color = Color.FromArgb(rgbColor.Red, rgbColor.Green, rgbColor.Blue); var hue = (int) color.GetHue(); var bright = (int) (color.GetBrightness()*100); if ((bright < 15 && hue < 50) || (bright <= 22 && hue < 30) || bright < 15) { LcdConsole.WriteLine("Color scan error"); return "ERR"; } //int sat = (int) (color.GetSaturation()*100); string colorStr = string.Format("R:{0} G:{1} B:{2} H:{3} B:{4} ", rgbColor.Red, rgbColor.Green, rgbColor.Blue, hue, bright); string c = " "; if ((bright > 56) || (hue > 42 && hue < 90 && (float) rgbColor.Red/rgbColor.Blue < 1.97) || (hue >= 90 && hue < 105 && bright > 40)) { c = "U - WHITE"; } else if (hue > 80 && hue < 135) { c = "B - GREEN"; } else if (hue > 135 && hue < 260) { c = "F - BLUE"; if (((float) rgbColor.Blue)/rgbColor.Red < 1.2f) c = "U - WHITE"; } else if (hue > 33 && hue < 70) { c = "D - YELLOW"; } else if (hue > 15 && hue < 30) { /*if (rgbColor.Blue >= 15 && hue > 15) { if (((float) rgbColor.Red)/rgbColor.Blue > 6.10f) c = "R - ORANGE"; else c = "L - RED"; } else c = "R - ORANGE";*/ c = "R - ORANGE"; } else if (hue <= 15) { c = "L - RED"; } c += " - " + colorStr; return c; }
/// <summary> /// Reads the RGB color. /// </summary> /// <returns>The RGB color.</returns> public RGBColor ReadRGB() { RGBColor rgbColor = null; if (uartMode == UARTMode.Mode4) { byte[] rawBytes = ReadBytes(6); var r = GetUInt16(rawBytes, 0); var g = GetUInt16(rawBytes, 2); var b = GetUInt16(rawBytes, 4); rgbColor = new RGBColor(r, g ,b); } return rgbColor; }