Wednesday, January 26, 2011

Project 6 - Modified Project

On page 58, the author provides a couple of extra exercises that are modifications of the Project 6 code. I decided to try my hand at the first one (second one to come) and gave it some thought today. The goal is to take an even number of LEDs and have the outer edges light up and then continue inward to the center of the line and then bounce back... so an even number of LEDs will work best... for this modification, I removed an LED so I have a total of 8 LEDs in the circuit.

I'm certain there are dozens of ways to do this - Project 6 uses a single array to control all the LEDs, but it occurred to me that in this exercise, I basically have two separate arrays running, each the reverse direction of the other. I took the code for Project 6 and modified it by breaking the initial array into two arrays (see two screen captures here for entire code). By doing this, I would also now require two directional variables and two currentLED variables to track the two current lighted LEDs. (Hope this makes sense...)

After trying to download the code to the Arduino, I encountered numerous syntax errors that were easy to fix (most of them involved forgetting to change a variable name to the new variables I created)... after fixing the syntax errors, the code downloaded and I was very happy to see it working as I hoped it would... see video below. (You can also download my modified program by clicking here.)

I left the 5k potentiometer in the mix as it allows me to control the speed of the two LEDs that light up... a very cool effect!


  1. I also decided to try both exercises and got the first one figured out but am hung up on the second one with the bouncing effect. did you ever get that exercise figured out? I have tried several things but I'm just not getting it. If you did get it to work and wouldn't mind providing a little push in the right direction that would be great.


  2. Hi, Steven.

    I wrote up about mod2 here: