@TeleOp
public class HelloRobot_ColorSensor extends LinearOpMode {
private NormalizedColorSensor test_color;
double hue; // <------ New codewhile (opModeIsActive()) {
telemetry.addData("Light Detected", ((OpticalDistanceSensor) test_color).getLightDetected());
NormalizedRGBA colors = test_color.getNormalizedColors();
hue = JavaUtil.colorToHue(colors.toColor()); // <------ New code@TeleOp
public class HelloRobot_ColorSensor extends LinearOpMode {
private NormalizedColorSensor test_color;
double hue; // <------ New code
@Override
public void runOpMode() {
test_color = hardwareMap.get(NormalizedColorSensor.class, "test_color");
waitForStart();
while (opModeIsActive()) {
telemetry.addData("Light Detected", ((OpticalDistanceSensor) test_color).getLightDetected());
NormalizedRGBA colors = test_color.getNormalizedColors();
hue = JavaUtil.colorToHue(colors.toColor()); // <------ New code
//Determining the amount of red, green, and blue
telemetry.addData("Red", "%.3f", colors.red);
telemetry.addData("Green", "%.3f", colors.green);
telemetry.addData("Blue", "%.3f", colors.blue);
//Determining HSV and alpha
telemetry.addData("Hue", JavaUtil.colorToHue(colors.toColor()));
telemetry.addData("Saturation", "%.3f", JavaUtil.colorToSaturation(colors.toColor()));
telemetry.addData("Value", "%.3f", JavaUtil.colorToValue(colors.toColor()));
telemetry.addData("Alpha", "%.3f", colors.alpha);
telemetry.update();
}
}
}if(hue < 30){
}
else if (hue < 60) {
}
else if (hue < 90){
}
else if (hue < 150){
}
else if (hue < 225){
}
else if (hue < 350){
}
else{
} if(hue < 30){
telemetry.addData("Color", "Red");
}
else if (hue < 60) {
telemetry.addData("Color", "Orange");
}
else if (hue < 90){
telemetry.addData("Color", "Yellow");
}
else if (hue < 150){
telemetry.addData("Color", "Green");
}
else if (hue < 225){
telemetry.addData("Color", "Blue");
}
else if (hue < 350){
telemetry.addData("Color", "Purple");
}
else{
telemetry.addData("Color", "Red");
}@TeleOp
public class HelloRobot_ColorSensor extends LinearOpMode {
private NormalizedColorSensor test_color;
double hue;
@Override
public void runOpMode() {
test_color = hardwareMap.get(NormalizedColorSensor.class, "test_color");
waitForStart();
while (opModeIsActive()) {
telemetry.addData("Light Detected", ((OpticalDistanceSensor) test_color).getLightDetected());
NormalizedRGBA colors = test_color.getNormalizedColors();
hue = JavaUtil.colorToHue(colors.toColor());
//Determining the amount of red, green, and blue
telemetry.addData("Red", "%.3f", colors.red);
telemetry.addData("Green", "%.3f", colors.green);
telemetry.addData("Blue", "%.3f", colors.blue);
//Determining HSV and alpha
telemetry.addData("Hue", JavaUtil.colorToHue(colors.toColor()));
telemetry.addData("Saturation", "%.3f", JavaUtil.colorToSaturation(colors.toColor()));
telemetry.addData("Value", "%.3f", JavaUtil.colorToValue(colors.toColor()));
telemetry.addData("Alpha", "%.3f", colors.alpha);
//Using hue to detect color
if(hue < 30){
telemetry.addData("Color", "Red");
}
else if (hue < 60) {
telemetry.addData("Color", "Orange");
}
else if (hue < 90){
telemetry.addData("Color", "Yellow");
}
else if (hue < 150){
telemetry.addData("Color", "Green");
}
else if (hue < 225){
telemetry.addData("Color", "Blue");
}
else if (hue < 350){
telemetry.addData("Color", "Purple");
}
else{
telemetry.addData("Color", "Red");
}
telemetry.update();
}
}
}