Monday, January 24, 2011

Project 5 - LED Chase Effect

I started off this project an LED short - it calls for 10, but I only have 9. This was fortunate as it forced to go through the code again and modify it for only 9 LEDs. I'm including a screen capture of my modified code here, but pay attention to the loops (for statements) where I had to reduce the count by 1... since we start counting at 0, the initializing loop (setting all pins to OUTPUT) will only count up to 8 (for a total of 9 LEDs).

But that's not the only place where the code had to be changed. Later in the process the direction variable is changed to -1 so the LEDs will light up in reverse... once again, the code must be modified so that the variable currentLED is set equal to 8.

A fun little project and reminded me of a 1 hour soldering job I took on to create my 3 year old son the Monster-B-Gone... a silly little project box that flashes a set of green LEDs and indicates the room is clear of baddies. It's funny that it took me over an hour to create that box but only about 10 minutes or so to wire up and program Project 5... (would have taken just a few minutes longer if I'd typed the code in manually instead of opening the author-supplied file).

You can easily modify this program for any number of LEDs (well, up to the maximum number of digital pins on the Arduino that are free) so if you don't have 10 LEDs, feel free to wire it up with 5 or 6... even a mix of colors will still get the point across if you examine the code and make an effort to understand what's happening.

One final note about this project - if you go back a few chapters where the author explains the basics of LEDs, you'll read that the Anode end will usually be a longer wire and the Cathode the shorter. Well, that doesn't hold up for every LED. I've taken a picture here of an LED resting on the flat notice and if you look closely, you'll see that it has the longer leg - it's a small difference, but it's definitely longer! All 9 LEDs in this bag are the same - long leg matches up to the flat notch. Check your LEDs and don't just assume that the longer leg is for the Anode side.



1 comment:

  1. I find this blog interesting, will be following. I did the same thing you're doing, start out with Mindstorms and continue to other microcontrollers from there. Except, instead of Arduino, I've decided to go with the Picaxe. A bit cheaper and you have more options as to what size of ucontroller you choose, eight pin up to forty pin.

    About the reversed LEDs. Some (cheap, as always) Chinese LEDs have the + and - mixed up, so just when you think you know how to wire up an LED correctly, you buy a couple off of eBay and find that they only work if reversed... I hate this as I'm never sure which way to plug an LED in now :D.

    ReplyDelete