- :-

Topics Covered

  • Variable Blocks
  • Naming Variables
  • Storing Variables
  • Reading Variables
  • Displaying Variables
  • Lesson Links

    Check Your Understanding:
    1. 1. What is a Variable?
    2. A block whose value never changes
      A "container" that holds a value for later use
      A letter like x or y
      The amount of difference between two readings
    3. 2. Why was a Variable used in this program?
    4. To store a value in one place and use it in another
      To put the Color Sensor into Ambient Light Intensity Mode
      To establish a Numeric Data Type
      To tell the robot how far to move
    Try It!
    Try it! 1

    Deleting Variable

    If you create a Variable you don't need, you can delete it by clicking on the Wrench tab ().




    Once you click the Wrench tab (), Project Property will open.
    On the bottom, it will list all elements that resides in your project such as Programs, Sounds, and Variables.

    To delete Variables, open the Variable tab.





    Select the Variable you would like to delete (in the image below, "CaveDarkness" is selected),
    and press the 'Delete' button to remove them out of the project.

    Did You Notice?

    Did you notice?

    Data Types
    You may have noticed that Variables have three different Types.
    This is because the EV3 recognizes three distinct types of values:
    Numeric values
    Example:Ultrasonic Sensor Value (number between 0 and 255)
    Text values
    Example:The text "MINDSTORMS" that the Display Block displays by default.
    Logic values
    Example:Answer to the question
    "Is the Touch Sensor being pressed right now?" (Yes or No)




    You can recognize the type of data that a connector or wire holds by its shape and color:




    Some Blocks will not accept Data Types that don't make sense.

    For instance, you cannot use a Math Block to add two Text Values together ("Dog" + "Pig" doesn't make sense).
    Mini Challenge

    Mini Challenge: Find the Black Line's Distance

    Program your robot to find the first black line on the floor of the cave,
    and report its distance from the entrance in Motor Rotations.

    Modify your Color Sensor attachment so it can detect a black line on the floor of the box.

    What value do you need to record once you have found the line? Hint: It's not the Color Sensor value.

    Program your robot to:
    - Drive into the box until it locates the black line on the ground
    - Recrod the Rotation Sensor value at that time (into a Variable)
    - Return to the entrance
    - Display the motor rotations value you recorded earlier on the screen

    + hint
    Try It!
    Try it! 2

    Very Long Wires

    In the EV3 Programming Language, you can use a very long wire
    to carry a value early in a program to another block later.


    Instead of putting the brightness reading in the Variable, wire it all the way over to the Display Block. Try it!
    What happens?
    You can do this in most programs, but it creates messy programs that can become difficult to read. Use variables to avoid making a mess!