Hello
I am going to make an project where i have to control 21 rgb leds. 16 of them is in pair and the other ones is separate. The thing is that i cant figure how to control one ore two only. The examples for tlc5940 works good, but i don't want a christmas tree.
For example i want led nr1 and 8 (channel (1-3) and (24-27) ) to be green.
wait 5 sec and then light up 2 other leds in one other color.
Okey sorry! The thing is that i am not good at this programming stuff , i am usually "back engineering" the code trying to understand what are doing what and then make it to work somehow.. but this example code don't have any basic stuff like turn one led on, there is a servo library for it to but i don't get the thing..
This is what i have tried, i believed it was just to give the channel a value and then use delay for on time :).
#include "Tlc5940.h"
void setup() {
// put your setup code here, to run once:
Tlc.init();
}
void loop() {
// put your main code here, to run repeatedly:
Tlc.update();
Tlc.set (1, 2000);
Tlc.set (2, 0);
Tlc.set (3, 1000);
delay(1000);
Tlc.clear();
}
/*
A simple 1-d oscilliscope: scan all the channels, setting the PWM output
value to 4x the analog pin 0 value (0 - 1024 * 4 = 4096). The value will
fade to zero as the channels keep scanning.
See the BasicUse example for hardware setup.
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
#include "Tlc5940.h"
#include "tlc_fades.h"
// which analog pin to use
#define ANALOG_PIN 0
// how many millis to strobe over all the LEDs
#define SCOPE_PERIOD (500 * NUM_TLCS)
#define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16)
TLC_CHANNEL_TYPE channel;
void setup()
{
Tlc.init();
}
void loop()
{
uint32_t lastMillis = millis();
tlc_addFade(channel, // led channel
analogRead(ANALOG_PIN) * 4, // start fade value (0-4095)
0, // 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);
}
(code tags added by moderator - please use them in the future)
/*
Basic Pin setup:
------------ ---u----
ARDUINO 13|-> SCLK (pin 25) OUT1 |1 28| OUT channel 0
12| OUT2 |2 27|-> GND (VPRG)
11|-> SIN (pin 26) OUT3 |3 26|-> SIN (pin 11)
10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 13)
9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9)
8| . |6 23|-> BLANK (pin 10)
7| . |7 22|-> GND
6| . |8 21|-> VCC (+5V)
5| . |9 20|-> 2K Resistor -> GND
4| . |10 19|-> +5V (DCPRG)
3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3)
2| . |12 17|-> SOUT
1| . |13 16|-> XERR
0| OUT14|14 15| OUT channel 15
------------ --------
- Put the longer leg (anode) of the LEDs in the +5V and the shorter leg
(cathode) in OUT(0-15).
- +5V from Arduino -> TLC pin 21 and 19 (VCC and DCPRG)
- GND from Arduino -> TLC pin 22 and 27 (GND and VPRG)
- digital 3 -> TLC pin 18 (GSCLK)
- digital 9 -> TLC pin 24 (XLAT)
- digital 10 -> TLC pin 23 (BLANK)
- digital 11 -> TLC pin 26 (SIN)
- digital 13 -> TLC pin 25 (SCLK)
- The 2K resistor between TLC pin 20 and GND will let ~20mA through each
LED. To be precise, it's I = 39.06 / R (in ohms). This doesn't depend
on the LED driving voltage.
- (Optional): put a pull-up resistor (~10k) between +5V and BLANK so that
all the LEDs will turn off when the Arduino is reset.
If you are daisy-chaining more than one TLC, connect the SOUT of the first
TLC to the SIN of the next. All the other pins should just be connected
together:
BLANK on Arduino -> BLANK of TLC1 -> BLANK of TLC2 -> ...
XLAT on Arduino -> XLAT of TLC1 -> XLAT of TLC2 -> ...
The one exception is that each TLC needs it's own resistor between pin 20
and GND.
This library uses the PWM output ability of digital pins 3, 9, 10, and 11.
Do not use analogWrite(...) on these pins.
This sketch does the Knight Rider strobe across a line of LEDs.
Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
#include "Tlc5940.h"
void setup()
{
/* Call Tlc.init() to setup the tlc.
You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
Tlc.init();
}
/* This loop will create a Knight Rider-like effect if you have LEDs plugged
into all the TLC outputs. NUM_TLCS is defined in "tlc_config.h" in the
library folder. After editing tlc_config.h for your setup, delete the
Tlc5940.o file to save the changes. */
void loop()
{
int direction = 1;
for (int channel = 0; channel < NUM_TLCS * 16; channel += direction) {
/* Tlc.clear() sets all the grayscale values to zero, but does not send
them to the TLCs. To actually send the data, call Tlc.update() */
Tlc.clear();
/* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for
one channel (15 is OUT15 on the first TLC, if multiple TLCs are daisy-
chained, then channel = 16 would be OUT0 of the second TLC, etc.).
value goes from off (0) to always on (4095).
Like Tlc.clear(), this function only sets up the data, Tlc.update()
will send the data. */
if (channel == 0) {
direction = 1;
} else {
Tlc.set(channel - 1, 1000);
}
Tlc.set(channel, 4095);
if (channel != NUM_TLCS * 16 - 1) {
Tlc.set(channel + 1, 1000);
} else {
direction = -1;
}
/* Tlc.update() sends the data to the TLCs. This is when the LEDs will
actually change. */
Tlc.update();
delay(75);
}
}
Sorry for bumping this once more but i am stuck. I have been on every single site google have given me, and i can't find any example to just control a few leds at a time whit the tlc5940.
This is going to be an fun project, all the stuff is on place and i only have to do the coding to finish it up.
I am so sorry Delta_G i had to unplug the power to make it work. Thx for your help!
this litle step to just make an led glow in that color i want will make an big differens for mankind!