Examples
Use-Case
This example program demonstrates how to use the AndyMark Proximity & Color Sensor in an FTC OpMode. It initializes the sensor from the robot's hardware map and continuously reads data while the OpMode is running. The program collects proximity information (distance to an object), the ambient light level, individual red, green, and blue color values, and a classified color name based on the sensor's readings. These values are then displayed on the Driver Station screen in real time, allowing users to see exactly what the sensor is detecting. This example is useful for testing the sensor, understanding its output, and troubleshooting sensor placement on a robot, and it can be used without needing in-depth programming knowledge.
Mounting Examples

Configuration


Code Example
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.ColorSensor;
import com.qualcomm.robotcore.hardware.DistanceSensor;
@TeleOp(name = "AMReleaseColorSensor")
public class AMReleaseColorSensor extends LinearOpMode
{
private ColorSensor sensor_color;
@Override
public void runOpMode()
{
sensor_color = hardwareMap.get(ColorSensor.class, "sensor_color");
waitForStart();
if (opModeIsActive())
{
while (opModeIsActive())
{
telemetry.addData("RED", sensor_color.red());
telemetry.addData("GREEN", sensor_color.green());
telemetry.addData("BLUE", sensor_color.blue());
/*
// This measurment is actually a unitless proximity measurement,
// so larger measurements = farther away, while
// smaller measurments = closer.
*/
telemetry.addData("Distance (m)", ((DistanceSensor) sensor_color).getDistance(DistanceUnit.METER));
telemetry.update();
}
}
}
}
Last updated
Was this helpful?