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
EV3-G program you can directly used in your STEM classes or in home
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.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

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
What is color?
If I ask you what the color of the ball on the picture below is, you will surely answer red without hesitation. All of you know what is meant when we talk about the color of an object, but what is actually color? This is one of the most natural concepts whose meaning and origin people often fail to realize.
- 9
- 0
- 4
- 3d_rotation 0