1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
while(1)
{
// Get the position of the line. Note that we *must* provide
// the "sensors" argument to read_line() here, even though we
// are not interested in the individual sensor readings.
unsigned int position = read_line(sensors,IR_EMITTERS_ON);
if(position < 1000)
{
// We are far to the right of the line: turn left.
// Set the right motor to 100 and the left motor to zero,
// to do a sharp turn to the left. Note that the maximum
// value of either motor speed is 255, so we are driving
// it at just about 40% of the max.
set_motors(5,75);
// Just for fun, indicate the direction we are turning on
// the LEDs.
left_led(1);
right_led(0);
}
else if(position < 3000)
{
// We are somewhat close to being centered on the line:
// drive straight.
set_motors(75,75);
left_led(1);
right_led(1);
}
else if(position == 4000)
{
set_motors(5,75);
delay_ms(1000);
set_motors(10,75);
delay_ms(1000);
set_motors(15,75);
delay_ms(1000);
set_motors(20,75);
delay_ms(1000);
set_motors(30,75);
delay_ms(1000);
set_motors(40,75);
delay_ms(1500);
set_motors(50,75);
delay_ms(1500);
set_motors(60,75);
delay_ms(10000);
if(position < 4000)
{
goto while(1);
|