Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //sets the threshold for reaction to light and sound
- #define SOUND_THRESHOLD 80
- #define MIC SENSOR_2
- #define THRESHOLD 48
- //task to find the line and stop
- task find_line()
- {
- while(SENSOR_3 >= THRESHOLD) //while in the white, go forwards
- {
- OnFwd(OUT_BC, 15); //Slow speed to stop in middle of line!!!
- Wait(50);
- }
- Off(OUT_BC); //turn off motors
- }
- //task to follwot eh track, keeping within the threshold
- task follow_track()
- {
- until(MIC >= SOUND_THRESHOLD); //does nothing until the mic is activated
- Wait(500);
- while(MIC <= SOUND_THRESHOLD) //prog can start now the bot has heard a noise
- {
- if (SENSOR_3 <= THRESHOLD)
- {
- OnRev(OUT_B, 15); //conditionals to determine which way the robot should travel to stay within the line
- OnFwd(OUT_C, 40);
- }
- else {
- ac OnRev(OUT_C, 15);
- OnFwd(OUT_B, 40);
- }
- }
- until(MIC >= SOUND_THRESHOLD) //stops on clap
- //Wait(500); //wait removed on last test
- Off(OUT_BC);
- }
- //main task
- task main()
- {
- //configures the sensors to respective ports
- SetSensorLight(IN_3);
- SetSensorType(IN_3, SENSOR_TYPE_LIGHT_ACTIVE);
- SetSensorSound(IN_2);
- //SENSORS ARE SET
- //initiaites the programs and the tasks above.
- Precedes (find_line, follow_track);
- }
Add Comment
Please, Sign In to add comment