The program from part 3 should be refactored and improved to make it easier to understand and support. We extract most of the repeatable behaviours in a loop and this reduces the size of the program three times in terms of the number of blocks used.
- #150
- 26 Oct 2015
- 2:44
Previous tutorials
Color sensor program for stopping on third line
English
In the previous video we stopped at the third line. We can now count the lines using the EV3 color sensor but the program was not very nice and had a lot of redundancy that now I would like to remove.
This here is the program. As you might remember we just copy and paste these 6 blocks 3 times. We are now counting to the third line. What happens if we want to count to the 5th line or to the 100th line, we must copy these 6 blocks a 100 times. This is not how programming is supposed to be. This whole program is very redundant. As a rule of thumb always when you are developing a software, program if you copy and paste something you are making a mistake. That's the professional rule of thumb, if you are copying and pasting in a software program you are adding redundancy and you are making a bug, that's the rule. We must remove these 12 blocks and what we would like to do is actually execute these 6 blocks 3 times and for this we have a special block called a Loop. We just move this whole program in a loop.
We would like to loop not for unlimited amount of time but for 3 loops. It's the same program, the same blocks but only we removed the redundancy and we added a loop. It's following the same idea, logic. Move forward detect a black line, stop, move forward, detect the table, stop. Then repeat this again and then repeat this one more time.
The robot again stops at a third line only this time the program is restructured and it is 3 times shorter and much more clear.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.

EV3 Basic Course. Introduction to robot programming, construction and sensor use
This course is designed for students, mentors and teachers that are completely new to LEGO Mindstorms EV3 robots and would like to start using them to learn, in classes or at competitions. It is quite different from previously built resources at FLLCasts because it makes no assumption on any previous knowledge and tries to introduce everything step-by-step.
- 38
- 193:26
- 30
Color Sensor
Very simple and basic introduction to the color sensor in the LEGO Mindstorms EV3 set. The first program is to stop at a line. Then we can move from stoping at line to counting lines and even more complex tasks.
- 8
- 0
- 3
- 3d_rotation 0

Instructors Remote Training
If you are working with students and you want to introduce Robotics to your class or you want to mentor a FLL team, but you are insecure about your technical knowledge in the Robotics field, then this is the right place for you. Having in mind teachers' busy schedule, we have design two different schedules and added an option to design one just for you. FLLCasts's Mindstorms EV3 Robotics Online Training is the perfect match for any teacher.
After the completion of each task the participant has to upload his solution for verification.
- 136
- 280:11
- 156

Color Sensor Theory and Practice
Very simple and basic introduction to the color sensor in the LEGO Mindstorms EV3 set. The first program is to stop at a line. Then we can move from stoping at line to counting lines and even more complex tasks.
- 5
- 0
- 0
- 3d_rotation 0

Instructors Remote Training
If you are working with students and you want to introduce Robotics to your class or you want to mentor a FLL team, but you are insecure about your technical knowledge in the Robotics field, then this is the right place for you. Having in mind teachers' busy schedule, we have design two different schedules and added an option to design one just for you. FLLCasts's Mindstorms EV3 Robotics Online Training is the perfect match for any teacher.
After the completion of each task the participant has to upload his solution for verification.
- 136
- 280:11
- 156

Color Sensor
Какво е цветът?
Ако ви попитам какъв е цветът на топката на картинката отдолу, ще ми отговорите червен.
Всеки знае какво имаме предвид, когато си говорим за цвят, но какво всъщност е цветът? Това е едно от най-естествените понятия, чиито значение и произход хората често не осъзнават.
- 9
- 0
- 4
- 3d_rotation 0