MIDI Callback ( #include <MIDI.h> ) for 9 PWM LEDs with TLC5940 ?

Hey ,

i try to change my ControlChange Midi-Callback Script from 5 PWM LED Outs ( 1RGB LED + 2 Ultrabright white LEDs) to 9 LED PWM Outs ( for 3 RGBs )with a TLC5940.

i cant figure out what Adress for the LEDs i have to use :confused:

the following Code works fine for me,but how to implement the "Tlc5940.h" library ?
ok,include,easy : #include "Tlc5940.h"
but what is the adress/port of the LEDs ( 0-15 ) now ???

or am i wrong totally ? :confused: thanks and best,
erich

working code for 5 PWM LEDs with Midi Callback

#include <Wire.h>
#include <MIDI.h>

const int led1 =  3;
const int led2 =  5;
const int led3 =  9;
const int led4 =  10;
const int led5 =  11;
int brightness1 = 0;
int brightness2 = 0;
int brightness3 = 0;
int brightness4 = 0;
int brightness5 = 0;
//const int switchPin = 6; //future midi send button,not Used now.

void HandleControlChange (byte channel, byte number, byte value) { 
  if (number == 3) {
    brightness1 = value;
  analogWrite(led1, brightness1);
  }
   if (number == 5) {
    brightness2 = value;
  analogWrite(led2, brightness2);
  } 
    if (number == 9) {
    brightness3 = value;
  analogWrite(led3, brightness3);
  } 
    if (number == 10) {
    brightness4 = value;
  analogWrite(led4, brightness4);
  } 
   if (number == 11) {
    brightness5 = value;
  analogWrite(led5, brightness5);
  } 
 else
{
    if (number == 23) {
    brightness1 = value;
    brightness2 = value;
    brightness3 = value;
    brightness4 = value;
    brightness5 = value;   

  analogWrite(led1, brightness1);
  analogWrite(led2, brightness2);
  analogWrite(led3, brightness3);
  analogWrite(led4, brightness4);
  analogWrite(led5, brightness5);
  } 
}  
}

void setup()
{
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    pinMode(led4, OUTPUT);
    pinMode(led5, OUTPUT);
                    
    MIDI.begin(MIDI_CHANNEL_OMNI);
    Serial.begin(115200);
    
    MIDI.setHandleControlChange(HandleControlChange);
}
    
void loop()
{
        MIDI.read(); 
}

The TLC5940 uses a memory buffer in the arduino. So controlling the LED is just a matter of setting the right bits in this buffer. This is made easy with a set command. Then you transfer the buffer to the chip with an update command. Look at the examples inside the libary folder.

Cool,thank you...
bu i still not understand how to do...could you give me another hint ? :cold_sweat:

Got it with some help... set " Tlc.init(); " in the setup and " Tlc.update(); " in the loop,define the LEDs with Tlc.set(0-15, value);

#include <Wire.h>
#include <MIDI.h>
#include "Tlc5940.h"

int brightness1 = 0;
int brightness2 = 0;
int brightness3 = 0;
int brightness4 = 0;
int brightness5 = 0;
const int switchPin = 6;

void HandleControlChange (byte channel, byte number, byte value) { 
  if (number == 1) {
    brightness1 = value;
  Tlc.set(1, value * 40); 
  }
   if (number == 2) {
    brightness2 = value;
  Tlc.set(2, value);
  } 
    if (number == 3) {
    brightness3 = value;
  Tlc.set(3, value);
  } 
    if (number == 4) {
    brightness4 = value;
  Tlc.set(4, value);
  } 
   if (number == 5) {
    brightness5 = value;
  Tlc.set(5, value);
  }
  if (number == 6) {
    brightness5 = value;
  Tlc.set(6, value);
  }
  if (number == 7) {
    brightness5 = value;
  Tlc.set(7, value);
  }
  if (number == 8) {
    brightness5 = value;
  Tlc.set(8, value);
  }
  if (number == 9) {
    brightness5 = value;
  Tlc.set(9, value);
  }
}

void setup()
{
    MIDI.begin(MIDI_CHANNEL_OMNI);
    Serial.begin(115200);
    MIDI.setHandleControlChange(HandleControlChange);
    Tlc.init();
}
    
void loop()
{
      Tlc.clear();
        MIDI.read(); 
        Tlc.update();
}