To take advantage of these capabilities, a variable will be needed. A variable, as the name suggests, is a program element that allows an attribute to be varied.

Begin by creating a variable that specifies the number of the LED addressed. Select the Make a Variable option under the Data & Blocks section of the Scripts tab.

Creating a Variable

Then enter the name “LED” in the New Variable dialog box that appears.

Naming the Variable

Then create a program with the following steps (as shown in the figure below).

  1. Set LED to 1
  2. Repeat 30
    1. Turn On LED
    1. Change LED by 1

The Repeat block is found under the Control category of the Scripts tab.

Turning on All the LEDs

This program initially sets the LED variable to 1. Then it repeats the following steps thirty times:

            Turn On LED 1

            Increase the LED variable by 1 (making its value 2).

            Turn On LED 2

            Increase the LED variable by 1 (making its value 3)


A program that repeats an action in this manner is called a loop. If this program were written out line by line, thirty lines of code would be required to turn on all of the LEDs. The use of a variable combined with a loop allows this action to be accomplished with just a couple of lines of code.

Once it has been verified that the code works, it can be saved for re-use at a later date by defining a new block, All_On. The term function is used to refer to a block of code that has been defined in this fashion.

Defining a New Block, All_On