Application Examples
Last updated
Was this helpful?
Was this helpful?
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.TouchSensor;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@TeleOp
public class HelloRobot_TouchSensor extends LinearOpMode {
TouchSensor test_touch; // Touch sensor Object
private DcMotor test_motor = null;
private Servo test_servo = null;
@Override
public void runOpMode() {
test_motor = hardwareMap.get(DcMotor.class, "test_motor");
test_touch = hardwareMap.get(TouchSensor.class, "test_touch");
// Wait for the game to start (driver presses PLAY)
waitForStart();
// run until the end of the match (driver presses STOP)
while (opModeIsActive()) {
if (touchSensor.isPressed()){
//Touch Sensor is pressed.
test_motor.setPower(0);
telemetry.addData("Touch Sensor", "Is Pressed");
} else {
//Touch Sensor is not pressed
test_motor.setPower(0.3);
telemetry.addData("Touch Sensor", "Is Not Pressed");
}
telemetry.update();
}
}
}