Help how do i do this?

So were tasked to make a robot do line tracking but everytime we touch the touchled sensor the robot must stop and then record the distance it does while line tracking until the touchled is touched again and we must do this like 4 times so… how do i code this?

So this is pretty simple you just have to say if the value of the sensor is less than a certain number(you should test this through the debugger) then run this program.

if(getColorGrayscale(LColor) <= 100)

This sounds like a “home work” problem. You need to break it down into smaller steps and write your program from there. Back in my day of early computing we did “flow charts” that outlined what we wanted the program to do. If I do a quick break down of your project:

Number of measurements = 0
Distance = 0; 
while Number of measurements < 4 
drive some distance along the line using line follow routine
if LED touched 
      Write distance on display
      Wait on LED touch
      number of mesurements = number of measurments + 1
      distance = 0 
  endif
endwhile