Project Home

Code Longhorn

Project LightCraft

Controlling the Lights


Now that the hardware is set up, let's take a look at the software. Software is the programs that tell the hardware what to do. We've already seen an example of a piece of software that controls the Arduino board: the Blink program. Now let's begin looking at software to control the lights through the Arduino board.

To begin, you'll first need to download the Code Longhorn framework. Right click on the link below and then save the file into your home directory. (Note that if you don't specify the directory, it will save to your Downloads directory, and you'll want to move it from there to your home directory.)

Code Longhorn Framework

Then, using the terminal from which you opened the Arduino IDE, type the following commands, which will unzip and expand the archive you just downloaded:

gunzip codelonghorn_framework.tar.gz
tar -xvf codelonghorn_framework.tar

Next, we need to open the Project LightCraft framework. From within the Arduino IDE, select File->Open. From there, navigate to your home directory and click on the codelonghorn folder. Within that directory, you'll find a grid_framework folder. Double click on that and and then again on grid_framework.ino.

The Arduino sketchbook called grid_framework should be opened.

This framework already consists of a few files (indicated by the tabs across the top), and you may add your own as you progress in the project. The pre-existing files are briefly described here, and we'll look at some of them more in-depth below.

Some important things to note before we begin programming:

Task 3.1: Blink Light (0,0)

Before you can use the lights we'll need to do one more thing: add a library to your Arduino setup. A library is a collection of already-written functions available for you to use. To add the FastLED library, you'll want to find the Sketch menu option on the top toolbar of the Arduino IDE. Click on Sketch, click on Include Library and then click Manage Libraries..., and a new window will pop up. Search for FastLED, and then click Install.

Now, let's look at the tests file. At the top of this file, there is a function called blink_light_0_0_example, which is provided for you. Take a careful look at that function and convince yourself that you understand its contents. You'll also notice that this function is called from the loop() function inside the grid_framework file. When you are ready, test the example by uploading it to the Arduino board (use the arrow pointing to the right as you did to blink the LED). The lights will first perform some tests where they alternate PaleVioletRed and SteelBlue, and then the code in the loop() function will begin to execute. In this case, that code is our blink_light_0_0_example().

If the code works properly, you should notice the first light (light 0) in the first strand (strand 0) blinking white. (Notice that we number from 0 and not 1!) Now, change the code to do the following things:

Task 3.2: Blink Light (0,0) and Light (2,4)

For our next test, let's blink both light (0,0) (i.e., the light on strand 0 at position 0) and light (2,4) (i.e., the light on strand 2 at position 4). Recall that we have seven strands of seven lights. If the first light is number 0, where do you suppose light 4 is?

Using the information you learned in Task 3.1, complete the blink_light_0_0_and_2_4() function in tests so that the first and last lights blink. Test your function by commenting out the call to blink_light_0_0_example in the loop() function in grid_framework and uncommenting the call to blink_lights_0_0_and_2_4() in that same function. Please ask if you need help!

Task 3.3: Blink All Lights

In your C++ tutorial, you learned how to use nested loops. Using nested loops, complete the blink_all_lights() function so that every light blinks. Once again, test it by commenting out any calls to other functions in the loop() function in grid_framework and uncommenting the call to blink_all_lights() in that same function.

Congratulations! You are able to control the lights! Now you are ready to begin doing more complicated things. Next, you'll learn to create basic patterns.