Variables

Variable it's a location in the memory of the EV3 Brick that can store a data value.

In other words, they are like magical boxes that hold different kinds of information, and you can use them to make your robot do all sorts of amazing things!

variables-blocks

How to make a variable?

Variable-intro

1- Press "Make a variable"

2- Name your "variable"

3- You can see that you have the variable you named.

You can make as many variables as you need.

Build the entire robot by:

If you have not done so

IMG-2019 IMG-2018

Variable + Operator + Gyro Sensor

gyro-variable

1- Set "theNumber" variable to 100

2- Repeat "theNumber" is less than the gyro Sensor

3- Motors make a Pivot turn to the right

4- Until"100 degrees" is less than the gyro Sensor (sensor already turn 100 degrees).

5- Stop moving

1-variable-gyro

This is a different robot from Exploration 2. So don't worry if it moves different from yours.

Repeat Variable 5 times

var BABY ROBOT

Notice that this gif/video is speed up.

No-wait-variable

1- Set "counting" variable to "5"

2- Repeat "5 times"

3- Motors making a 360 degrees spin turn at the speed of 50%

4- "counting" add 1, inside the loop

5- The loop run for 5 times. Stop moving

Variables 2 ways of making the robot repeat movement

var-repeat

And:

Screenshot 2024 05 14 at 10.27.27

The video/gif it's x4 speed.

"Repeat"

Variable-way1-2
2-1-variable-repeat5

This is a different robot: way-2 exploration. So don't worry if it moves differently.

1- Set "counting" variable to "5"

2- Repeat "5 time"s

3- Motors making a 360 degrees spin turn at the speed of 50%

4- "counting" add 1, inside the loop

5- Wait for 1 second

6- The loop run for 5 times. condition is met. Stop moving

"Repeat Until"

fast
Screenshot 2024 05 14 at 10.29.03

1- Set "counting" variable to 0

2- Repeat "counting" is EQUAL to 4

3- Motors make 360 degrees spin turn at the speed of 50%

4- Until"counting" is MORE than 4.

5- Wait for 1 second

6- Stop moving

Display the variable

variable-number1-10

The number starts counting from 1 (since you set it to "set CountinNumber to 1")

variable-Display-num1-10

1- Set variable "CountingNumber" to 1

2- Repeat 10 times:

3- Display [together]"Number" and variable "CountingNumber" at line of "CountingNumber"

4- Change "CountingNumber" by 1 (add one everytime it run the loop)

Observations: Why is variable important for programming?

Time for a quiz!

Question goes here

Challenge for you

variable-1-10

Hint:

-> Variable name: CountingNumber.

-> Use "Repeat" block for 10 times.

Variable-you

Notice it's the same as the Display Variable shown above!