Application Examples
Last updated
Was this helpful?
Was this helpful?
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.TouchSensor;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
@TeleOp
public class LimitSwitchTest extends LinearOpMode {
// Define variables for our touch sensor and motor
TouchSensor test_magnetic;
DcMotor test_motor;
@Override
public void runOpMode() {
// Get the touch sensor and motor from hardwareMap
test_magnetic = hardwareMap.get(TouchSensor.class, "test_magnetic");
test_motor = hardwareMap.get(DcMotor.class, "test_motor");
// Wait for the play button to be pressed
waitForStart();
// Loop while the Op Mode is running
while (opModeIsActive()) {
// If the Magnetic Limit Swtch is pressed, stop the motor
if (test_magnetic.isPressed()) {
test_motor.setPower(0);
} else { // Otherwise, run the motor
test_motor.setPower(0.3);
}
telemetry.addData("Arm Motor Power:", test_motor.getPower());
telemetry.update();
}
}
}