Advertisement
roll11226

COLOR

Jan 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.robotcore.hardware.ColorSensor;
  4. import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
  5. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  6. import com.qualcomm.robotcore.hardware.Servo;
  7.  
  8. /**
  9.  * Created by FTC-computer on 1/24/2018.
  10.  */
  11.  
  12. public class COLOR extends LinearOpMode {
  13.     int redtimes = 0;
  14.     int bluetimes = 0;
  15.  
  16.     private int ColorContinuation = 0;
  17.  
  18.  
  19.     private ColorSensor colorSensor = null;
  20.  
  21.     private Servo Vservo = null;
  22.     private Servo Hservo = null;
  23.  
  24.     @Override
  25.     public void runOpMode() throws InterruptedException {
  26.         colorSensor = hardwareMap.get(ColorSensor.class, "color_sensor");
  27.         colorSensor.enableLed(true);
  28.         Hservo = hardwareMap.get(Servo.class, "horizontal_servo");
  29.         Vservo = hardwareMap.get(Servo.class, "vertical_servo");
  30.     }
  31.  
  32.     public void RedAll()
  33.     {
  34.         Hservo.setPosition(0.5);
  35.         sleep(300);
  36.         Vservo.setPosition(0.6);
  37.         sleep(1000);
  38.  
  39.         while (ColorContinuation < 36)
  40.         {
  41.             if (colorSensor.red() > colorSensor.blue())
  42.             {
  43.                 redtimes++;
  44.                 ColorContinuation++;
  45.             }
  46.             else
  47.             {
  48.                 bluetimes++;
  49.                 ColorContinuation++;
  50.             }
  51.         }
  52.  
  53.         if (redtimes > bluetimes)
  54.         {
  55.             Hservo.setPosition(0);
  56.             sleep(750);
  57.             telemetry.addData("recognized color: ", "red");
  58.             telemetry.update();
  59.             Hservo.setPosition(0.4);
  60.         }
  61.         else
  62.         {
  63.             Hservo.setPosition(1);
  64.             sleep(750);
  65.             telemetry.addData("recognized color: ", "blue");
  66.             telemetry.update();
  67.             Hservo.setPosition(0.6);
  68.         }
  69.  
  70.         Hservo.setPosition(0.5);
  71.         sleep(100);
  72.         Vservo.setPosition(0);
  73.         sleep(3000);
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement