Guest User

Untitled

a guest
May 24th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #define path_state 60       // Thresholds
  2. #define white_state 20
  3. #define speed_normal 85     // Speeds
  4. #define plus_correction 95
  5. #define minus_correction 65
  6. #define pause 50            // Wait time after sensor change
  7.  
  8. task main()
  9. {
  10.  
  11.  
  12.     SetSensorLight(IN_1);
  13.     SetSensorLight(IN_2);
  14.     SetSensorLight(IN_3);
  15.    
  16.     bool check = false; // If true = Stop, if false = keep going
  17.    
  18.     while(true)
  19.     {
  20.         OnFwd(OUT_AB,speed_normal); //20
  21.    
  22.         while(true)
  23.             {
  24.                 if(IN_2 >= path_state)
  25.                 {
  26.                     if(IN_3 <= white_state && IN_1 <= white_state)
  27.                         {}
  28.                     else if(IN_1 >= white_state)
  29.                         {
  30.                         OnFwd(OUT_A, minus_correction);
  31.                         OnFwd(OUT_B, plus_correction);
  32.                         }
  33.                     else if(IN_3 >= white_state)
  34.                         {
  35.                         OnFwd(OUT_A, plus_correction);
  36.                         OnFwd(OUT_B, minus_correction);
  37.                         }
  38.                     else
  39.                         {
  40.                         ClearScreen();
  41.                         NumOut(60, LCD_Line1, 1);
  42.                         break;
  43.                         }
  44.                        
  45.                 } //40
  46.                
  47.                 if(IN_2 <= path_state)
  48.                 {
  49.                     if(IN_3 <= white_state && IN_1 <= white_state)
  50.                     {
  51.                         while(true)
  52.                         {
  53.                             Wait(pause);
  54.                             if(IN_2 >= path_state)
  55.                                 {
  56.                                 check = true;
  57.                                 Off(OUT_AB);
  58.                                 }
  59.                             else
  60.                                 {
  61.                                 NumOut(60, LCD_Line2, 2);
  62.                                 break;
  63.                                 }
  64.                         }
  65.                
  66.                
  67.                         if(IN_1 >= white_state)
  68.                             {
  69.                             OnFwd(OUT_A, minus_correction);
  70.                             OnFwd(OUT_B, plus_correction);  //60           
  71.                             }
  72.                         else if(IN_3 >= white_state)
  73.                             {
  74.                             OnFwd(OUT_A, plus_correction);
  75.                             OnFwd(OUT_B, minus_correction);
  76.                             }
  77.                         else
  78.                             {
  79.                             NumOut(60, LCD_Line3, 3);
  80.                             break;
  81.                             }
  82.                     }
  83.            
  84.        
  85.                 while(check)
  86.                     {
  87.                         // Do fancy shit with Lego Gun here
  88.                     }
  89.             }  
  90.         }
  91.     }
  92. }
Add Comment
Please, Sign In to add comment