In this tutorial, we would implement a program that finds the minimum and maximum value detected by the sensor and stores this two values in an array.
- 04 Oct 2017
- Mindstorms Competitions, Mindstorms Sensors, Light & Color Sensor, Programming
- D.Staykov, K.Mitov
Sensor Raw Value
First, we detect the raw sensor for the given sensor. The block is available in the "advance" blocks palette.
Compare of previous Min
Finding minimum and maximum values is one of the first programs in every programming course. In the implemented program, we constantly compare the currently detected value from the sensor with the value that is already considered a minimum. If the currently detected value is less than the known minimum that the currently detected value should become the minimum.
The comparison as pseudo code looks like this
if currentValue < knownMinimum then currentValue is set to the value of knownMinimum
The same logic is implemented in the program with the only difference that the knownMinimum is stored in an array.
Storing min and max in an array
The array is organized in the following way. Cell 0 stores Minimum for Sensor 1. Cell 1 stores Maximum for Sensor 1.
Cell 2 stores Mimimum for Sensor 2. Cell 3 stores Maximum for Sensor 2.
So the odds store the minimum values and the evens stores the maximums.