Programming a menu. Storing in Arrays. WRO Elementary 2013. Pro Preview

The challenge for this video is to program a menu that is controlled from the LEGO Mindstorms EV3 brick screen. 

  • #220
  • 17 Jul 2016
  • 5:19

We use the menu to program the robot on the spot for the order of the different blocks. In this way the robot knows where to put the different blocks. 

English

Our next challenge is after we have loaded the blocks to program their order. And for this we'd use a menu like this one here. And now the robot asks us for the order of the different blocks. And we'll persist this order in an array in the brick.

When we start the program

it now asks us for the order and we must enter the first block. And that's the first block that is loaded here. So, we can say, let me just fisrt load them. Load the blocks.

Now we have the order and we consider this block to be blue, so we have blue, red, blue, green, green. And the first block will be blue. We have blue written on the screen and we just enter. There is a sound. This means that the brick accepts and it now persists that the first block is blue the second block is red and for red we'll just move to red. Again, enter. Then the next one is blue. Enter. Then the next one is green. And the last one is green. And we have now entered all the blocks and their order in the brick. As a program this look like this. The program for the blocks looks like this. We have an array. This array is called InRobot and we create arrays from the red parts of the blocks and we can create a new array. This is an array operation but for array we just write a numeric array. And we can call this array different ways. And InRobot is actually the array in which we store the order of the different blocks. You can imagine an array as

different cells with different values that are one next to the other and we store different values in these cells. So, this is an array. Oh, that's not very good array. But I'll take a box. We have array, array of 5 elements. And in these 5 elements we'll store different values. If the value is for the colour blue, then we'll store 1, for green we'll store 2 and for red we'll store 3. And at the end we'll have this whole array filled with the different values of the different blocks. How do we do this? We have a loop and this loop loops for 5 times because we have 5 different blocks that we must detect the colour of. And we choose the colour. And this block choice colour returns 1, 2 or 3 depending on what we have chosen on the screen. So, if on the screen we have the text blue,

if on the screen we have blue, then this block will return 1. If on the screen we have green, then it will return 2. And if on the screen we have red, then it will return 3. And that's the purpose of this block choice colour. It's actually the menu that we are going to program. And if we return 1, we store this value 1 into the array. And we store this into the first cell of the array. So, we have the array of 5 different elements.

And the first time we are into the loop we store 1. Because the first block is 1. If the second block is red, in the second cell we'll store 3. And if the third is blue, we'll store 1. And if the fourth and the fifth are green, we'll store 2 and 2. And this is how our array will look like at the end of our program entering into the ChoiceBlock. And let's see how it's implemented.

Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons