If you replicate this hallway lighting project, you will be the envy of your family, friends, and neighbors.
The software was a bit of a challenge. I hadn't used a rotary encoder before, and neither had I used interrupts. My implementation may well be seen by others as poor practice, but what I've done works for me in this situation. Fortunately, I'm not after massive speed, since the main use in this case is for mood lighting -- not fast-paced disco lighting (well, not yet anyway).
Interrupt 1 is used for the push button. It just detects that it's been pressed, then sets a flag. Interrupt 2 is used to detect that the rotary encoder has moved from a detent position. The interrupt routine then waits for the encoder to rest at another detent position, registering the direction in which it was turned. This then changes the display mode up or down by one unit. While the encoder remains between detent positions, the display doesn't update. It's quite difficult to set the encoder to rest in a non-detent position, so I'm not worried about the display freezing up.
The code needs more work with more modes and effects to be added, so it's still a work in progress. What I have at the moment is four modes as follows:
- DIY color mix. In this mode, the amount of red, green, and blue can be adjusted by hand using three of the potentiometers to create a static color of one's choice. The fourth potentiometer is used to adjust the overall brightness.
- Color fade. In this mode, all of the pixels fade from green, to blue, to red, and back to green. Two of the potentiometers are used to vary the speed of fade effect and the overall brightness.
- Rainbow wave. This mode applies a full rainbow along the entire length of the strip and moves the colors along in an anticlockwise direction. Two of the potentiometers are used to control the speed and the overall brightness. A third potentiometer is used to adjust the number of full rainbows along the length of the strip. This effect is based on the color wheel example code provided by Adafruit.
- Rainbow cycle. This mode applies a partial rainbow onto the strip and moves it in an anticlockwise direction. Speed and overall brightness can be adjusted. (I might end up scrapping this one, since it isn't sufficiently different from the rainbow wave and color fade modes.)
The LCD display is used to present the currently active mode by name, along with the values of each of the four potentiometers (usually shown from 0% to 100%). For modes that don't make use of all four potentiometers, "---" characters are displayed for the unused components, and the software ignores any modifications to the unused devices. It would have been nice to label the dial functions, but the display I used doesn't have enough space. I suppose I could alternate the top line with the mode name and the dial functions, but I know what the dials do, and that's all that matters to me.
Introducing my 8x8x8 3D RGB LED cube project
I have plenty of other ideas I can use to enhance my hallway lighting system, but I haven't implemented any of them as yet. The main reason for this is that I'm eager to move on to my next project -- an 8x8x8 3D RGB LED cube.
I became interested in building my cube after running across Max Maxfield and Duane Benson's Kickstarter project for a Screw-Block Proto-Shield for Arduino. When I contacted Max about the availability of this shield, his reply included links to articles on EETimes discussing some of his projects.
Reading these articles, I found references to YouTube videos of LED cubes that others had built. I had seen some 4x4x4 cubes before and had passed them by, but Max's articles inspired me to start my own 8x8x8 cube project.
Max and I share a passion for flashing LEDs, and Max says he is very interested to see how I tackle this quite difficult task. Plenty of other folks have succeeded in building their own 8x8x8 cubes, and I intend to use their experience and knowledge in my version of the build, although I might do some things slightly differently.
I ordered a thousand 5mm RGB common anode LEDs and a reel of 20-gauge tinned copper wire about a week ago at the time of this writing. Everything just arrived, so I can commence the construction of my cube very soon.
I just opened the bag of LEDs and tipped them into a container. I have to say that my heart sank as I realized just how many LEDs need testing before I use them. (There seem to be a lot more than you were expecting when they are sitting on the table in front of you.)
I think I'll do the testing in batches. In the meantime, the following websites and/or articles owned/written by Kevin Darrah, Sean Michael Ragan, and Nick Schulze have proved to be very useful. You should also check out this site. And, of course, I cannot fail to mention this article by Max Maxfield that sparked me off into building my own LED cube.
I will be documenting this cube project, with accompanying photos and videos, in future columns. In the meantime, I welcome any comments and questions relating to my hallway lighting project.