Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma config(Sensor, S3, ultrasonic_sensor, sensorEV3_Ultrasonic)
- #pragma config(Sensor, S4, color_sensor, sensorEV3_Color)
- #pragma config(Motor, motorB, left_motor, tmotorEV3_Large, PIDControl, driveLeft, encoder)
- #pragma config(Motor, motorC, right_motor, tmotorEV3_Large, PIDControl, driveRight, encoder)
- //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
- // Global Variables //
- bool obstacle_found = false;
- const int color_breakpoint = 20;
- int LightInt; // Used to display and keep track of the color detected by the sensor
- // Functions //
- void set_drive_speed(int left_speed, int right_speed) // Sets the speed of the car based on user input
- {
- setMotorSpeed(left_motor, left_speed);
- setMotorSpeed(right_motor, right_speed);
- }
- void display_light_value() //displays colour value on brick screen
- {
- LightInt = getColorReflected(color_sensor);
- displayCenteredBigTextLine(4, "%d", LightInt);
- }
- void line_tracking()
- {
- if (LightInt > color_breakpoint) { // If line is not found
- set_drive_speed(15, 8);
- } else if (LightInt <= color_breakpoint) { // if line is found
- set_drive_speed(8, 15);
- }
- } // line_tracking
- /*
- void obstacle_avoidance()
- {
- // set obstacle_found to false
- } // obstacle_avoidance
- void obstacle_check()
- {
- // if the distance sensor reads something, and is below a certain threshold, set obstacle_found to true
- } // obstacle_check
- */
- // Main //
- task main()
- {
- while(true) {
- display_light_value();
- line_tracking();
- }
- /*
- while (true) { // Loop that runs the whole time the program is running
- // check for obstacle
- obstacle_check();
- if (obstacle_found) {
- obstacle_avoidance(); // Function that takes over when the obstacle is found.
- } else {
- line_tracking(); // Normal funcition for tracking the line and moving
- } // if
- } // for
- */
- } // main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement