24 Channel PWM LED driver .. how do I use it? (Beginner programmer!)

Hi guys!

I'm an engineering student so the electronics and stuff is all fine, but programming wise .. haven't really touched that much! I have some knowledge of C/C++ but nothing like this.

I have a circuit using 24 LEDs, and have an Adafruit TLC5947 chip to drive them all with varying brightness etc.

I have been picking apart the sample code provided by Adafruit for the chip and have been looking in the library to try understand what I have to do to get an LED to light up .. however, no success so far.

I am using this chip: Adafruit 24-Channel 12-bit PWM LED Driver - SPI Interface [TLC5947] : ID 1429 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits and the library and sample code can all be found at that link if you click around a bit. (I'll link them below anyway though)

The tutorial I have followed so far: Overview | TLC5947 and TLC59711 PWM LED Driver Breakouts | Adafruit Learning System (Setting up the chip and connecting it the same way).

Link to library: Programming - Library Reference | TLC5947 and TLC59711 PWM LED Driver Breakouts | Adafruit Learning System (its the TLC5947 one). The example code is within the library.

I can get the sample code to run fine as far as I can tell. But when I try to break it down to figure out how to control the chip .. I suffer.

My first goal right now is to just get the chip to turn on one LED, say .. output 11 on the chip.

It looks like I have to use a combination of setLED and setPWM (to set the light and then the brightness) and then write(); to update it to the chip, yet I cannot get this to work at all.

So, any help would be appreciated! I'm sure its pretty simple once you get an idea of what you're supposed to do, but at the moment, I am stumped :smiley:

I'm pretty new to this .. so be nice! Also if you could explain 'why' I select something (if you know) that would be great as it'll help me understand it and not have to ask again :smiley:

Thanks in advance for any help :slight_smile:

Please post your edited code so we can take a look. Please use code tags when posting it.

I have managed to get it to turn on the LEDs! As I imagined… it does seem simple once I got it to work.

This is what I have at the moment. Its just going around all 24 outputs and turning them on at max brightness. Am I using the commands correctly? Also, could you possibly explain what the code within setup is doing? I had a look online and its a pin that enables … the board? So you can switch it on and off while its operating? In which case I can probably remove all that? (but keep the tlc.begin)

#include "Adafruit_TLC5947.h"


#define NUM_TLC5974 1               //one board
#define data   4                    //pin 4
#define clock   5                   //pin 5
#define latch   6                   //pin 6
#define oe  -1                      // set to -1 to not use the enable pin (its optional) (Dont know what this does)

Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5974, clock, data, latch);

void setup() {
  Serial.begin(9600);               // vvvvvv Not sure what any of this does
  
  tlc.begin();
  if (oe >= 0) {
    pinMode(oe, OUTPUT);
    digitalWrite(oe, LOW);
  }
}                                   // ^^^^^^ Just that its initialising and setting up .. something

void loop() {

  for(int i=0;i<25;i++)
  {
    setLEDPWM(i,4095);    //sets all 24 outputs to maximum brightness PWM.
    tlc.write();          //updates new setting (can place outside loop?)
  }
}

void setLEDPWM (uint8_t lednum, uint16_t pwm)
{
    tlc.setPWM(lednum, pwm);
    tlc.write();  
}




/*
void setLED (uint8_t lednum, uint16_t r, uint16_t g, uint16_t b)
{
    tlc.setLED(lednum, r, g, b);
    tlc.write();  
}
*/

I couldn’t get the commands to work from within the main loop so had to create functions to call them. Kept getting ‘expected primary-expression before numeric constant’ etc. Also some of the comments may seem a bit pointless but they’re just there for my benefit!

Thanks!