Think of it like a shift register for Pulse Width Modulation (PWM).
/* LucidTronix HSB RGB necklace * uses TLC5940 chip. for details see: * http://www.lucidtronix.com/tutorials/6 * Control rgb color by specifying * Hue saturation and brightness. * This code shows a rainbow. * It is okay to daiy-chain the chips * just change the NUM_TLCS constant * in the Tlc5940.h file. * This code uses an arduino color library * available here: * http://www.lucidtronix.com/tutorials/19 */#include "Tlc5940.h"#include "tlc_fades.h"#include "color.h"// how many millis to strobe over all the LEDsTLC_CHANNEL_TYPE channel;Color cur_color(1,1,1);int scope_period = (200 * NUM_TLCS);int led_period = scope_period / (NUM_TLCS * 16);float hue = 0;void setup(){ Tlc.init();}void loop(){ hue += 0.001; if ( hue >=1 ) hue = 0; float sat = 1.0; float val = 0.5; cur_color.convert_hcl_to_rgb(hue,sat,val); uint32_t lastMillis = millis(); int cur_val = channel % 3; int color_component = 0; if ( cur_val == 0) color_component = cur_color.red*16; else if ( cur_val == 1) color_component = cur_color.green*16; else if ( cur_val == 2) color_component = cur_color.blue*16; tlc_addFade(channel, // led channel color_component, // start fade value (0-4095) color_component, // end fade value (0-4095) lastMillis + 2, // start millis lastMillis + (uint16_t)scope_period / 4 // end millis ); if (channel++ == NUM_TLCS * 16) { channel = 0; } uint32_t currentMillis; do { currentMillis = millis(); tlc_updateFades(currentMillis); } while (currentMillis - lastMillis <= led_period);}
| Title | Description | # | Cost | Link | Picture |
| TLC5940 | IC LED DRIVER PWM CONTROL 32-QFNValue:3 V ~ 5.5 V | 1 | $3.37 | Link |
|
| ATMEGA168A-AU | IC MCU AVR 16K FLASH 32TQFPValue:1.8 V ~ 5.5 V 20MHz | 1 | $2.43 | Link |
|
| Potentiometer | POT ROTARY, Linear 10K OHM 9MM SNAPINValue:10k | 1 | $0.76 | Link |
|
| RGB LED | LED RGB SMD DIFF 4-PLCCValue:1.9V Red, 3V Green, 3V Blue | 5 | $0.55 | Link |
|
| Switch | SWITCH SLIDE DPDT 6VDC 0.3A SMTValue:DPDT | 1 | $0.44 | Link |
|
| LED SMD | LED 3X1.5MM 568NM Green Clear SMDValue:2.2V Green | 16 | $0.18 | Link |
|
| Button 6mm Through Hole | Tactile Switch Through Hole SPST-NO 0.05A 12VValue:0.05A @ 12VDC | 2 | $0.1 | Link |
|
Comments: