Line Following robot programming

Hello, I managed to build the hardware part of a line following robot but with only 3 home-made IR sensors with IR led and phototransistors. Now I have come to the programming part and hit a question: is it better to use an Interrupt to detect when the line goes right or left ? Or should I use IF and WHILE statements?

My idea was to use the central IR sensor to detect when the robot was on the line. If the line goes left, it triggers the left sensor and the whole robot goes left until the center IR sensor detects the line again. Is this logic sound?

Thank you.

Now I have come to the programming part and hit a question: is it better to use an Interrupt to detect when the line goes right or left ?

No. You still have to do something about the fact that the line has been detected to have moved. You can't do that in an ISR.

In fact, I don't know what would trigger the interrupt. I would expect that you are using analogRead() to read the sensors, and analog values can't trigger interrupts.

Ok. So just to be clear, the interrupts only help in detecting the line going left/right but I can't order the motors to change direction ?

The use of if, while and for statements would add significant delay to the running code? Would that interfere with the reaction time it takes to change direction of the motors when the line went, for example, left?

Sajuuk: Ok. So just to be clear, the interrupts only help in detecting the line going left/right but I can't order the motors to change direction ?

No. As PaulS said, you are probably looking for a light level to go up or down. That is an analogRead. You just need to do them constantly.

The use of if, while and for statements would add significant delay to the running code?

No.

Would that interfere with the reaction time it takes to change direction of the motors when the line went, for example, left?

The processor runs much faster than your robot, don't worry about it.

I understand. Thank you PaulS and Nick Gammon for your replies. I'll now go and program somethig :).