Your first OpMode#
This reads a colour sensor on port 0 and prints what it sees. It is about as small as a useful Expander OpMode gets.
package org.firstinspires.ftc.teamcode;
import com.botbuilders.bbr.BBRDigitalExpander;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@TeleOp(name = "BBR: First OpMode")
public class BBRFirstOpMode extends LinearOpMode {
@Override
public void runOpMode() {
BBRDigitalExpander exp = hardwareMap.get(BBRDigitalExpander.class, "expander");
telemetry.addData("sensor on port 0", exp.getSensorType(0));
telemetry.update();
waitForStart();
while (opModeIsActive()) {
telemetry.addData("colour class", exp.getColorClass(0));
telemetry.addData("encoder 0", exp.getEncoderCount(0));
telemetry.update();
}
}
}
Press INIT and you should see what kind of sensor is on port 0 before you even start. If it says EMPTY, the sensor isn’t detected — check the connection.
Teaching it a colour#
getColorClass() returns 0 until you have taught the board what to look for. Teaching takes one call, and the result is saved to the board’s flash automatically:
exp.teachColor(0, 1); // what the sensor sees right now is "colour 1"
Run that once, with the target held in front of the sensor, and from then on getColorClass(0) returns 1 whenever it sees that colour again — including after a power cycle, and including in a completely different OpMode.
There is a full walkthrough in Colour sensors.
How reads work#
Every everyday getter — encoders, sensors, colours, distances — is served from a snapshot that the driver refreshes about every 10 ms.
This matters because it means asking four questions in one loop iteration costs one I2C transaction, not four:
int a = exp.getEncoderCount(0);
int b = exp.getEncoderCount(1);
boolean red = exp.seesColor(2, 1);
double mm = exp.getDistanceMm(3);
// all four answers came from the same snapshot, one transaction
It also means those values are mutually consistent — they were all captured at the same instant by the board, not read one at a time while the robot moved.
You don’t have to manage this. Just call the getters.
What to do next#
- Four extra encoders → Encoders
- Detect a colour → Colour sensors
- Detect an object → Distance sensors
- Get the board to do the watching for you → Digital outputs and triggers