Lesson 9 Worksheet 9.1 – Understanding variables
A variable is small piece of computer memory for storing data. What makes variables so useful is that this data can change while the program is running, hence the name variable.
Variables store numbers like 10, 106, 1,482 etc. and allow a computer program to do maths, this is something that computers are very good at.
The Edison robot has two types of variables that are called ‘bytes’ and ‘words’. Byte variables can store numbers that range from 0 to 255. Word variables can store numbers that range from -32,767 to +32,767.
To make variables easy to use we give them names. This helps us humans remember what type of information is stored in them. In EdWare, you can name your variables just about anything you like. You could name one ‘Fred’, but that might not be a very helpful name for remembering what type of information is stored in Fred. A better name might be ‘Light_Level’. This type of name makes it very easy to remember what the variable is used for and what type of data to find there.
Now that you know about variables let’s create one in EdWare for our next programs.
Click the ‘Add Variable’ button in the top left corner and a pop up box will appear.
Type in the name of your variable as ‘Light_Level’, select the variable range as +/-32767 (word) and set the initial value to zero. Now click OK and your variable will be added to the variables table in the bottom right corner.
What type of variable would you use for storing the following numbers (byte or word)?
12 _________, 192 _________, 801 _________, -42 _________, 27,901_________