Advertisement
Guest User

Untitled

a guest
May 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #pragma config(Sensor, S1,     UltraSonicSensor, sensorEV3_Ultrasonic)
  2. #pragma config(Sensor, S2,     GyroSensor,     sensorEV3_Gyro)
  3. #pragma config(Sensor, S4,     LightSensor,    sensorEV3_Color)
  4. #pragma config(Motor,  motorA,          LeftMotor,     tmotorEV3_Large, PIDControl, encoder)
  5. #pragma config(Motor,  motorB,          LiftMotor,     tmotorEV3_Medium, PIDControl, encoder)
  6. #pragma config(Motor,  motorD,          RightMotor,    tmotorEV3_Large, PIDControl, encoder)
  7. //*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
  8.  
  9. void setMotor(int x, int y) {
  10.     motor[LeftMotor] = x;
  11.     motor[RightMotor] = y;
  12.  
  13. }
  14.  
  15. void detectObject(){
  16.         const int distanceToMaintain = 4;
  17.         int currentDistance = SensorValue[UltraSonicSensor];
  18.         if(((distanceToMaintain - currentDistance) < 1) && ((distanceToMaintain - currentDistance) > -1)){
  19.             setMotor(0, 0);
  20.             motor[LiftMotor] = -10;
  21.             sleep(500);
  22.             setMotor(10, -10);
  23.             sleep(1500);
  24.             setMotor(10, 10);
  25.             sleep(1000);
  26.             motor[LiftMotor] = 10;
  27.             sleep(500);
  28.             setMotor(-10, -10);
  29.             sleep(1000);
  30.             setMotor(-10, 10);
  31.             sleep(1500);
  32.  
  33.         }
  34.  
  35. }
  36.  
  37.  
  38. task main()
  39. {
  40.     int color = 8;
  41.     while(true){
  42.  
  43.         int light = SensorValue[LightSensor];
  44.         displayCenteredBigTextLine(6, "LightSensor: %3d cm", light);
  45.         while (SensorValue[LightSensor] < color) {
  46.             setMotor(30, 0);
  47.             sleep(300);
  48.             detectObject();
  49.         }
  50.  
  51.         while (SensorValue[LightSensor] >= color){
  52.             setMotor(5, 20);
  53.             detectObject();
  54.         }
  55.         sleep(50);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement