Advanced Light/Color sensors calibration for a maximum value for a single sensor Pro Preview

Following the Advance Light/Color sensors calibration for a minimum value for a single sensor tutorial, in this one, we continue with finding the maximum value detected by a sensor and storing this value in an array.

  • #642
  • 04 Oct 2017
  • 4:10

Sensor Raw Value

We take the sensor raw value and use it both for minimum and for maximum. 

Compare of previous Max

Initially, the Maximum value is set to -12345. This is a very small value and we are sure that even the first detection of a value from the sensor will be more than the initial maximum value. After that, the comparison is the following

if currentValue > knownMaximum then currentValue is set to the value of knownMaximum

The same logic is implemented in the program with the only difference that the knownMaximum is stored in an array.

We read from the maximum value and compare with the cell with index 3 from the array. Then we do a SWITCH and IF the value read from the array is less than the value from the Sensor we write this value in the array.


In the previous tutorial from the course we stopped at calibrating the minimum value for sensor 2 and in this tutorial we'll calibrate the maximum value again for a single sensor - for sensor 2.

First, the robot moves back. We must set the power to -20 but we have our sensors right here and I'll place the sensors before the line something like this. And then I'll start the program again. The robot moves for about a second, calibrates but nothing is displayed on the brick screen. And in our next program we'll display the newly calibrated values on the brick screen.

What I'll do is again I'm in the loop and this loop I would like to read the maximum value that we currently have for sensor 2. And this maximum value is stored in the numeric array and this numeric array is MinMaxArray and we read and then we have an operation - array operation. Let me just move this to the center of the screen. And zoom this in. So, I would like to read cell with index 3. So, I have 0 and 1 for the first sensor and 2 and 3 for the second sensor. And after I read this value I must compare it. And I compare to the currently detected value by the raw sensor. Zoom out. Take the value from here. Attach it right here. Zoom in. And we must compare. So, if the current detected by the sensor maximum value this is the one stored in the array. So, if the one stored in the array is less than the currently detected , then and only then we must write the currently detected to the array. I will do this. We have a switch and for this switch again set it as logic, flat

and right here, move it to the center of the screen we take the array.

We read value from the array and read numeric array, an operation to write at a certain index. So, we take the array, we want to write in the cell with index 3 and the value that we want to write is the value that we have from the sensor. So, zoom out again, take the value from the sensor, move it right here. Zoom in and at the end write the final result again into the array. Write numeric array.

And in this way at the end we'll have the minimum and maximum value for sensor 2 set to the minimum and maximum value detected by the sensor itself. And this will continue for about a second. So, let's start the program and let's see what happens.

Lessons with this tutorial

This tutorial is used in the following lessons

  1. FIRST LEGO League Competition. Constructing and Programming a Robot Base / Advanced Light/Color Sensor Calibration

    1. ***Tutorial****

    2. ***Tutorial****

    3. ***Tutorial****

    4. ***Task****

    5. ***Tutorial****

    6. Advanced Light/Color sensors calibration for a maximum value for a single sensor
    7. ***Tutorial****

    8. ***Tutorial****

    9. ***Task****

    10. ***Tutorial****

    11. ***Tutorial****

    12. ***Tutorial****

    13. ***Task****

    14. ***Tutorial****

    15. ***Tutorial****

    16. ***Tutorial****

    17. ***Tutorial****

    18. ***Tutorial****

    19. ***Task****

    20. ***Program****

    21. ***Program****