06 Mission Instructions

Your mission is to design a timer, with a loud alarm, and then send it wherever you need to keep track of time. 

5. Code: Creating a Variable

Before we plan our timer program, we are going to learn a few new features of Bloxter. 


We don’t want to write a completely new program every time we change the length of the timer, so we need to create an easy place in our code to update how long we want the timer to run.


To do this, we will create a variable. You may have used variables in math class, where a word, letter, or symbol represents a number. In Bloxter, we can make up a word and use it to keep track of a number. 


For example, if we invent a variable named “frog” and set it equal to six, and then we invent a variable named “toad” and set it equal to four, we can ask Bloxter to add “frog” plus “toad” and print the result (see below). 


Now our robot can add! 


So how did we create these variables and then add them together? In order to make our own variables, we will need to use Advanced Bloxter


Variables are found in the bright blue section labeled Variables in Advanced Bloxter. When we want to make a new variable, we go to Variables and then click on "Create variable". Once you do this a new window will open for you to name the new variable. Type your name into the box and then click OK. Your new variable will now appear in the Variables section. 


Now, you will also have blocks to set the variable, change it by [1], and the variable block. You can drag the block that holds the variable name into any Bloxter Block that needs a number. We did that when we added our variables frog and toad together. 




Before we go on, let’s practice with variables. Write a new program that uses a loop (try repeat) and create a variable that counts to 100 (By 1’s, 5’s, or even 25’s!). Have the robot print each number as it counts. The print block will tell your robot to show each number as it counts. When you run your program, a window will pop up that says "Output" and will write out each number as your robot counts. If you are stuck, take a look at our example program below. 


The blocks to control the buzzer can be found under Actuators. You can control the buzzer in several different ways. But, one way we can control it is by creating a Variable! Take a look at the sample program below to try it yourself.