Guest User

Untitled

a guest
Apr 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1.  
  2. //sets the threshold for reaction to light and sound
  3. #define SOUND_THRESHOLD 80
  4. #define MIC SENSOR_2
  5. #define THRESHOLD 48
  6.  
  7. //task to find the line and stop
  8. task find_line()
  9. {
  10.     while(SENSOR_3 >= THRESHOLD)  //while in the white, go forwards
  11.     {
  12.         OnFwd(OUT_BC, 15);    //Slow speed to stop in middle of line!!!
  13.         Wait(50);
  14.     }
  15.  
  16.     Off(OUT_BC);            //turn off motors
  17. }
  18.  
  19. //task to follwot eh track, keeping within the threshold
  20. task follow_track()
  21. {
  22.  until(MIC >= SOUND_THRESHOLD); //does nothing until the mic is activated
  23.  
  24.        Wait(500);
  25.  
  26.  while(MIC <= SOUND_THRESHOLD)  //prog can start now the bot has heard a noise
  27.             {
  28.                 if (SENSOR_3 <= THRESHOLD)
  29.                       {
  30.                       OnRev(OUT_B, 15);        //conditionals to determine which way the robot should travel to stay within the line
  31.                       OnFwd(OUT_C, 40);
  32.                       }
  33.                       else {
  34.       ac              OnRev(OUT_C, 15);
  35.                       OnFwd(OUT_B, 40);
  36.                       }
  37.             }
  38.             until(MIC >= SOUND_THRESHOLD)  //stops on clap
  39.  
  40.        //Wait(500);    //wait removed on last test
  41.        Off(OUT_BC);
  42. }
  43.  
  44. //main task
  45. task main()
  46. {
  47. //configures the sensors to respective ports
  48. SetSensorLight(IN_3);
  49. SetSensorType(IN_3, SENSOR_TYPE_LIGHT_ACTIVE);
  50. SetSensorSound(IN_2);
  51.           //SENSORS ARE SET
  52.  
  53. //initiaites the programs and the tasks above.
  54. Precedes (find_line, follow_track);
  55.  
  56. }
Add Comment
Please, Sign In to add comment