One of the smartest things you could do in any software program is to extract logic in small reusable, simple, understandable units. In EV3-G these are called Blocks and we are going to extract the logic for finding a minimum and maximum for each of the sensors in a new block.
- #645
- 04 Oct 2017
- 2:37
- LEGO MINDSTORMS, LEGO MINDSTORMS EV3
- FIRST LEGO League, EV3-G, Sensors, EV3, Array, Light and Color Sensor, FLL, Programming
Why blocks
First rule of EV3-G - if the program is taking more than one screen it is difficult to use and understand it.
By extracting into a new block you turn this:
Into this:
Much better, easier and understandable.
English
Now that we've seen that there are no problems on the display and that we detect the correct minimum and maximum values the next thing that we must do on our program is to extract part of the logic into a new block. And the logic that we are extracting is the one that finds the minimum and maximum values of the all 4 sensors.
We select with the mouse all the blocks that are in the loop
like this then we go to Tools>MyBlock Builder
and in the MyBlock Builder first we must set a name and it's FindMinMax so that's a nice way to name it. So, we find the minimum and maximum and we should select some kind of an icon. Now, there are a couple of ways to think about it. First, probably we can select the icon with the array because we are doing some operations with an array or we can have some icon with a sensor. So, we prefer the one with an array and then we finish.
And now I can finally zoom in
and we have a nice little program that's easy to understand and it's a program where we init the array, we move, we find the minimum and maximum,
we do this for about 1 second, we stop and then we display all the values on the display. So, in this way we've extracted our complex logic for finding the minimum and maximum into a block and now we can use this block in other programs that we are also developing.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.

FIRST LEGO League Competition. Constructing and Programming a Robot Base
This course if used by teams, mentors and students to structure the preparation for the Robotics Game of the FIRST LEGO League Robotics Competitions. One thing that is common each year at FLL is that experience matters a lot. Our goal with this course is to quickly bring new teams up to speed with experienced teams and to share some new tricks, patterns, constructions with the more experienced teams.
- 42
- 249:53
- 10
Advanced Light/Color Sensor Calibration
Would you like to resolve all the problems with the light/color sensors that you have? And to make all of them work in a predictable, stable way even when using more than one MINDSTORMS colour sensors.
When using Color sensors it is important to calibrate them depending on the light conditions in your venue. In this way, the calibrated sensor will show values between 0 and 100 independent of the light conditions. But using the default EV3 colour calibration available in the colour sensor block could lead to unpredicted problems that are difficult to track and resolved especially when used with multiple Color sensors. So in this series of tutorial we implement the calibration ourselves discussing the principles of colour sensor calibration.
- 15
- 0
- 4
- 3d_rotation 0