Description
In this lab, we investigate the use of pulse-width modification to fake an analog signal from a digital one, by quickly pulsing a digital signal at varying frequencies. The circuit is a simple modification from last week's, whereby the three LEDs are connected to PWM-capable pins (numbers 9, 10, and 11) through a 220 ohm resistor. The circuit was easy to implement, though I took a few extra minutes to organize the three circuits in such a manner that the LEDs were directly adjacent to each other.
To soften the light from the LEDs and merge them into a solid color, I constructed a simple diffuser with a wax paper cup. Inside, an approximately conically-shaped aluminum foil housing reflects the LED light and directs it toward the top of the cup, where a tissue is held with a rubber band. On the side of a cup is a small hole where the LEDs fit into the housing. It's fairly effective, though I would prefer some diffuser paper, white latex, or other diffusing material for robustness. Unfortunately, I have none of these more robust matreials.
I created two small programs to demo the LED circuit. Both take some string of characters via serial communication as input and display output via the LEDs connected to the Arduino. The first program, "rgb keypress" is as suggested in the homework spec; provide an arbitrary number of "r", "g", or "b" characters, and a representative color will be displayed. Every appearance of a character increases the brightness of its respective LED by 1/16. In this code, any combination and number of characters will produce a color. For instance, "rgb" would produce a (16, 16, 16) triple, "rrrrgg" would produce (64, 32, 0), and "rgbrgb" would produce (32, 32, 32).
The second program, "sentence colors" takes any arbitrary sentence and converts it to a sequence of colors that fade between each other. When the program is loaded in the Arduino, it randomly chooses a color palette. The user then inputs, via serial communication, a sentence, and the program converts the entire sentence to a string of colors that fade from one to the next, pausing at each letter for about one second. As an example, let's assume the randomly assigned palette includes the color red for "h", cyan for "i", and yellow for "!". The sentence "hi!" would then be output first by red for one second, a fade to cyan, pause for one second, and a fade to yellow. It will then turn off the LEDs and continue the cycle again.
Components Used
1- Arduino Uno
3- 220 ohm resistors
3- LEDs (red, green, blue)
1- small wax cup
1- rubber band
1- sheet of facial tissue
1- 10cm by 10cm sheet of aluminum foil
Code
For cleanliness, I've attached the code rather than pasted it here:
Download RGB keypress
Download Sentence colors
Photos
Are attached below.
- Login to post comments