Advertisement
roll11226

becon detect

Feb 2nd, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import com.qualcomm.hardware.modernrobotics.ModernRoboticsI2cColorSensor;
  4. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  5.  
  6. /**
  7. * Created by Ori on 02/02/2017.
  8. */
  9.  
  10. public class beacone_detected_blue extends LinearOpMode{
  11. private HardWare11226 m_hardware = new HardWare11226();
  12. private boolean ranonce = false;
  13.  
  14.  
  15. @Override
  16. public void runOpMode() throws InterruptedException {
  17. m_hardware.init(hardwareMap);
  18. waitForStart();
  19. while (opModeIsActive() && !ranonce)
  20. {
  21. beaconDetect();
  22. ranonce = true;
  23. }
  24. }
  25.  
  26. private int counter = 0 ;
  27. public void beaconDetect() {
  28. while (counter != 5 && counter != -5) {
  29. if (m_hardware.color_sensor.red() > m_hardware.color_sensor.blue() + 2) {
  30. counter--;
  31. } else if (m_hardware.color_sensor.blue() > m_hardware.color_sensor.red() + 2) {
  32. counter++;
  33. }
  34. idle();
  35. }
  36.  
  37. if (counter == 5)
  38. {
  39. telemetry.addData("count", counter);
  40. telemetry.update();
  41. m_hardware.color_sensor.enableLed(true);
  42. } else if (counter == -5)
  43. {
  44. telemetry.addData("count", counter);
  45. telemetry.update();
  46. .enableLed(true);
  47. .enableLed(false);
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement