Go Down

Topic: Receive multiple midi notes (or "chords") to control in realtime RGB leds? (Read 4066 times) previous topic - next topic

axxel

Finally....

I solved it!

Cubase was the error.

With Ableton it works like a charm.

Here is the video:

https://www.youtube.com/watch?v=Z6MT9A6StZQ

Here is the working code with TLC5940 and Ableton:

Code: [Select]
#include "Tlc5940.h"

byte midirgb[128];

//These are the midi commands to interact with the arduino

byte midi_on = 0x90;
byte midi_off = 0x80;
byte location_byte;
byte in_note;
byte in_volume;
boolean newNote = false;

void check_midi()
 {

     if (Serial.available()>2)
     {
       location_byte = Serial.read(); //read first byte
       in_note = Serial.read();       //read next byte
       in_volume = Serial.read();     //read final byte
       if(location_byte == midi_on || location_byte == midi_off) newNote = true;
     }
 }

void setup() {
Tlc.init();
Serial.begin(31250);
}

void loop() {

for (int i=0; i <= 47; i++){ 
check_midi();
if(newNote){
  if (location_byte == midi_on) midirgb[in_note] = in_volume;
  if (location_byte == midi_off) midirgb[in_note] = 0;
   newNote = false;
  }
}

   Tlc.clear();
   for (int i=0; i <= 15; i++){
     RGBTLCSet256(i,midirgb[i],midirgb[i+16],midirgb[i+32]);
   }
   Tlc.update();
 
}

void RGBTLCSet256(byte ledstrip, byte r, byte g, byte b)
{
  if (ledstrip==0){
   Tlc.set(15, map(r,0,255,0,4095));
   Tlc.set(14, map(g,0,255,0,4095));
   Tlc.set(13, map(b,0,255,0,4095));
  }
 
  if (ledstrip==1){
   Tlc.set(12, map(r,0,255,0,4095));
   Tlc.set(11, map(g,0,255,0,4095));
   Tlc.set(10, map(b,0,255,0,4095));
  }
 
  if (ledstrip==2){
   Tlc.set(9, map(r,0,255,0,4095));
   Tlc.set(8, map(g,0,255,0,4095));
   Tlc.set(7, map(b,0,255,0,4095));
  }
 
  if (ledstrip==3){
   Tlc.set(6, map(r,0,255,0,4095));
   Tlc.set(5, map(g,0,255,0,4095));
   Tlc.set(4, map(b,0,255,0,4095));
  }
 
  if (ledstrip==4){
   Tlc.set(3, map(r,0,255,0,4095));
   Tlc.set(2, map(g,0,255,0,4095));
   Tlc.set(1, map(b,0,255,0,4095));
  }
 
  if (ledstrip==5){
   Tlc.set(0, map(r,0,255,0,4095));
   Tlc.set(31, map(g,0,255,0,4095));
   Tlc.set(30, map(b,0,255,0,4095));
  }
 
  if (ledstrip==6){
   Tlc.set(29, map(r,0,255,0,4095));
   Tlc.set(28, map(g,0,255,0,4095));
   Tlc.set(27, map(b,0,255,0,4095));
  }
 
 if (ledstrip==7){
   Tlc.set(26, map(r,0,255,0,4095));
   Tlc.set(25, map(g,0,255,0,4095));
   Tlc.set(24, map(b,0,255,0,4095));
  }

 if (ledstrip==8){
   Tlc.set(23, map(r,0,255,0,4095));
   Tlc.set(22, map(g,0,255,0,4095));
   Tlc.set(21, map(b,0,255,0,4095));
  }
 
 if (ledstrip==9){
   Tlc.set(20, map(r,0,255,0,4095));
   Tlc.set(19, map(g,0,255,0,4095));
   Tlc.set(18, map(b,0,255,0,4095));
  } 
 
 if (ledstrip==10){
   Tlc.set(17, map(r,0,255,0,4095));
   Tlc.set(16, map(g,0,255,0,4095));
   Tlc.set(47, map(b,0,255,0,4095));
  } 
 
 if (ledstrip==11){
   Tlc.set(46, map(r,0,255,0,4095));
   Tlc.set(45, map(g,0,255,0,4095));
   Tlc.set(44, map(b,0,255,0,4095));
  } 
 
 if (ledstrip==12){
   Tlc.set(43, map(r,0,255,0,4095));
   Tlc.set(42, map(g,0,255,0,4095));
   Tlc.set(41, map(b,0,255,0,4095));
  } 
 
 if (ledstrip==13){
   Tlc.set(40, map(r,0,255,0,4095));
   Tlc.set(39, map(g,0,255,0,4095));
   Tlc.set(38, map(b,0,255,0,4095));
  } 
 
 if (ledstrip==14){
   Tlc.set(37, map(r,0,255,0,4095));
   Tlc.set(36, map(g,0,255,0,4095));
   Tlc.set(35, map(b,0,255,0,4095));
  } 
 
 if (ledstrip==15){
   Tlc.set(34, map(r,0,255,0,4095));
   Tlc.set(33, map(g,0,255,0,4095));
   Tlc.set(32, map(b,0,255,0,4095));
  }   
}


Thanks a lot for your help :)  :)  :)

Go Up