Intro: Adding a Dimmer to Your DOTKLOK
I love my new home-built DOTKLOK (http://aomalley.org/dotklok/), but at night, that darn clock is too bight. I decided to add a photoresistor, also called a photocell, as a dimmer and hack the 'KLOK a little. Photoresistors are basically resistors that change their resistance based on the amount of light that hits it's face. They are very inexpensive and easy to incorporate into projects.
Step 1: Open the DOTKLOK
Unplug your DOKKLOK from the power source and get a soft cloth for your work surface. A microfiber cloth would be best, but here I'm using a clean bath towel.
Un-screw the screws and nuts on the DOTKLOK case and lay it out on a soft cloth so you don't scratch the surfaces of the acrylic faces.
You'll then want to carefully remove the SURE LED Matrix. Mark the plug and socket so you know how to hook it up again. Then, unplug it from the main board. Set it aside for now.
Step 2: Prototyping the Photo-resistor on the Arduino
With the LED Matrix removed, I spent some time with a prototyping Breadboard Arduino from Dale Wheat at http://www.dalewheat.com/store/ and some code from @ladyada at http://www.ladyada.net/learn/sensors/cds.html to work out how to incorporate the photo-resistor into the board.
Note: Not all photo-resistors are created equal and you may have to fool around with the settings to get it to work with your configuration.
Step 3: Simple Schematic
The circuit is very simple. The DOTKLOK board includes a 'hackable' prototyping area with pinouts for the Arduino's A0-A3, D2-D3, and D12-D13...along with corresponding GND and 5V holes.
After prototyping the photoresistor on the breadboard, I determined that a 1K resistor would work best. So, looking at the available pins, I'll be using Analog-0 to read the value of the photoresistor.
If you're looking for a good tutorial on adding photoresistor to your Arduino project, check out @ladyada's site at http://www.ladyada.net/learn/sensors/cds.html.
Step 4: Attach Pull-down Resistor to the Photoresistor
Because there are limited pinouts on the DOTKLOK board, I decided to add the pull-down resistor to the photoresistor directly. I like to use shrink-wrap tubing to keeps things neat and to keep the leads from touching.
Step 5: More Shrink-wrap Tubing
Add more shrink-wrap tubing to make it as neat as possible. Use a heat-gun to shrink the tubing when it is all in place. Now there are three leads. One for one side of the photoresistor by itself (to 5V), one lead for the resistor itself (to GND), and one lead that includes both the 1K resistor and the photoresistor (to Analog-0).
Step 6: Attach Ribbon Cable
I found some solid-conductor ribbon cable laying around the shop and I pulled off three conductors. I stripped the ends and added more shrink-wrap tubing to each conductor. Then, I soldered the leads to the ribbon cable. Using the heat-gun, shrink the tubing around the newly soldered conductors. Remember to add the shrink-wrap tubing BEFORE you solder the conductors to the leads of the photoresistor. You only forget once and then you always remember to do it first.
Step 7: Bendy Ribbon-Cable
Bend the ribbon-cable around the board and place the photoresistor near the top of the DOTKLOK. Make sure the correct leads are arranged at the correct terminals.
Step 8: Solder It In
Solder the correct leads to A0, GND, and 5V. It's now time to close your DOTKLOK back up. Connect up the LED Matrix and attach it back the way it was originally.
Step 9: Modify the Code - Add the Brightness Function
Now that the photoresistor is installed in the DOTKLOK and the hardware is put back together, it's time to add some code to tell the LED Matrix to dim according to the value received on pin A0. The first modification is to the HT1632.pde file. Here you need to add the brightness function. The raw reading from A0 (0-1024) will be converted, or mapped, to the value expected by the HT1632 driver (0-15). So, the function will receive a passed integer called intensity that will have a value of 0-15. I added some code to increase the intensity at high levels, and decrease it a really low levels.
Step 10: Define the Global Variables
Next, we'll define two global variables. In the dotklok_rev_1_2.pde file, add the two lines included in the photo below. One for the pin to read the value, and the other for the value itself.
Step 11: Modify the Code - Read the Value
Next, we need to read the value of the photoresistor and call the brightness function to change the brightness of the LED Matrix. You can see the 'map' function used to map the analog value to the 0 - 15 value expected by the HT1632 driver.
These two lines of code will need to be added at the bottom of the do-while loop of each animation in time_animations.pde.