Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.firstinspires.ftc.teamcode;
- import com.qualcomm.robotcore.hardware.ColorSensor;
- import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
- import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
- import com.qualcomm.robotcore.hardware.Servo;
- /**
- * Created by FTC-computer on 1/24/2018.
- */
- public class COLOR extends LinearOpMode {
- int redtimes = 0;
- int bluetimes = 0;
- private int ColorContinuation = 0;
- private ColorSensor colorSensor = null;
- private Servo Vservo = null;
- private Servo Hservo = null;
- @Override
- public void runOpMode() throws InterruptedException {
- colorSensor = hardwareMap.get(ColorSensor.class, "color_sensor");
- colorSensor.enableLed(true);
- Hservo = hardwareMap.get(Servo.class, "horizontal_servo");
- Vservo = hardwareMap.get(Servo.class, "vertical_servo");
- }
- public void RedAll()
- {
- Hservo.setPosition(0.5);
- sleep(300);
- Vservo.setPosition(0.6);
- sleep(1000);
- while (ColorContinuation < 36)
- {
- if (colorSensor.red() > colorSensor.blue())
- {
- redtimes++;
- ColorContinuation++;
- }
- else
- {
- bluetimes++;
- ColorContinuation++;
- }
- }
- if (redtimes > bluetimes)
- {
- Hservo.setPosition(0);
- sleep(750);
- telemetry.addData("recognized color: ", "red");
- telemetry.update();
- Hservo.setPosition(0.4);
- }
- else
- {
- Hservo.setPosition(1);
- sleep(750);
- telemetry.addData("recognized color: ", "blue");
- telemetry.update();
- Hservo.setPosition(0.6);
- }
- Hservo.setPosition(0.5);
- sleep(100);
- Vservo.setPosition(0);
- sleep(3000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement