Help in programming the reactive led coffee table

Good afternoon community!
I apologize for my English!
I’m new to this programming theme!
I’m developing a work for school on a reactive leds desk and I need your help with programming.

I will use:

100 - leds
25 - IR receiver (black)
16 - IR Emitter (Transparent)
2 - TLC5940
2 - CD74HC4067
7 - TLC274

Video of the original project:

Creation

Result

Images of the assembly scheme:

Code:
Block Diagram:

I’ve tried everything to do this programming, but I could not.
I want when an object approaches the IR pair, I want the led to have a brightness of 4095, and when the object is no longer on the IR pair, I want the LED to gradually go from 4095 to 0(fade),and remain at zero until the object is over again.

I tried programming through the 74HC4067, but I could not, because I do not know where to add the programming of the TLC5940.
This programming makes the reading of analog signals, and it is through them that I want to control the LEDs on the tlc5940.

/******************************************************************************
Mux_Analog_Input
SparkFun Multiplexer Analog Input Example
Jim Lindblom @ SparkFun Electronics
August 15, 2016
*/

const int selectPins[4] = {8, 6, 5, 4}; // S0~2, S1~3, S2~4
const int zOutput = 5; 
const int zInput = A0; // Connect common (Z) to A0 (analog input)

void setup() 
{
  Serial.begin(9600); // Initialize the serial port
  // Set up the select pins as outputs:
  for (int i=0; i<4; i++)
  {
    pinMode(selectPins[i], OUTPUT);
    digitalWrite(selectPins[i], HIGH);
  }
  pinMode(zInput, INPUT); // Set up Z as an input

  // Print the header:
  Serial.println("Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7\tY8\tY9\tY10\tY11\tY12\tY13\tY14\tY15");
  Serial.println("---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---\t---");
}

void loop() 
{
  // Loop through all eight pins.
  for (byte pin=0; pin<=15; pin++)
  {
    selectMuxPin(pin); // Select one at a time
    int inputValue = analogRead(A0); // and read Z
    Serial.print(String(inputValue) + "\t");
  }
  Serial.println();
  delay(100);
}

// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-7.
void selectMuxPin(byte pin)
{
  for (int i=0; i<4; i++)
  {
    if (pin & (1<<i))
      digitalWrite(selectPins[i], HIGH);
    else
      digitalWrite(selectPins[i], LOW);
  }
}

If you could give me some tips on how to do it, I thank you immensely, because I need this project for the school!

Oficial datasheet:

CD74HC4067

TLC5940

If you could give me some tips on how to do it,

1) Do not center justify text, it is anoying. 2) Start off with the examples in the TLC5940 libiary, get them working and see how to use the libiary. 3) You will see you have a memory buffer that you place stuff in and it appears on the LEDs. 3) Incorporate the simple sensor detection into the code, by setting / clearing the parts of the memory buffer associated with what the sensors are reporting.

Grumpy_Mike: 1) Do not center justify text, it is anoying. 2) Start off with the examples in the TLC5940 libiary, get them working and see how to use the libiary. 3) You will see you have a memory buffer that you place stuff in and it appears on the LEDs. 3) Incorporate the simple sensor detection into the code, by setting / clearing the parts of the memory buffer associated with what the sensors are reporting.

I'm sorry for the text in the center. I know how to do a code of TLC5940 and CD74HC4067, the only thing I do not know is to join both codes!

How do I incorporate this code in the other code of the mux? I can not incorporate because of the "for", do you have any idea how I can do it?

The code of fades is something like this:

include "Tlc5940.h" //led driver

include "tlc_fades.h"

void setup () {

Tlc.init ();

{

//tlc_addFade( channel, startValue, endValue, startMillis, endMillis ) tlc_addFade (10, 4000, 0, 1000, 4000); }

}

void loop () {

tlc_updateFades ();

}

This tells you what you need:-

tlc_addFade( channel, startValue, endValue, startMillis, endMillis )

The channel number is the number of the LED you want to light.

You will have a number of the sensor that is close to the LED. If you have wired things up correctly simply transfer ( use the same number ) of the sensor number where you detect the object, into the channel you want to light. If you have not wired it up so they are the same then use an array to link the two, where the array index is the sensor number and the contents of the array is the number of light you want to activate.

I can not incorporate because of the "for",

No idea what you mean. I don't know what is stopping you.

Grumpy_Mike:
This tells you what you need:-

tlc_addFade( channel, startValue, endValue, startMillis, endMillis )

The channel number is the number of the LED you want to light.

You will have a number of the sensor that is close to the LED. If you have wired things up correctly simply transfer ( use the same number ) of the sensor number where you detect the object, into the channel you want to light. If you have not wired it up so they are the same then use an array to link the two, where the array index is the sensor number and the contents of the array is the number of light you want to activate.

No idea what you mean. I don’t know what is stopping you.

Can you explain this in particular to mux code?
I did not understand what you’re saying, sorry for my ignorance.

I’m trying to put an instruction(if) with what I want to do, but it does not work.

/******************************************************************************
Mux_Analog_Input
SparkFun Multiplexer Analog Input Example
Jim Lindblom @ SparkFun Electronics
August 15, 2016
*/

const int selectPins[4] = {8, 6, 5, 4}; // S0~2, S1~3, S2~4
const int zOutput = 5;
const int zInput = A0; // Connect common (Z) to A0 (analog input)

void setup()
{
Serial.begin(9600); // Initialize the serial port
// Set up the select pins as outputs:

for (int i=0; i<4; i++)
{
pinMode(selectPins*, OUTPUT);*
_ digitalWrite(selectPins*, HIGH);_
_
}*_

* // Print the header:*
* Serial.println(“Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7\tY8\tY9\tY10\tY11\tY12\tY13\tY14\tY15”);*
* Serial.println("—\t—\t—\t—\t—\t—\t—\t—\t—\t—\t—\t—\t—\t—\t—\t—");*
}
void loop()
{
* // Loop through all eight pins.*
* for (byte pin=0; pin<=15; pin++)*
* {*
* selectMuxPin(pin); // Select one at a time*
* int inputValue = analogRead(A0); // and read Z*
* Serial.print(String(inputValue) + “\t”);*

* }*

/*
if (selectMuxPin(15) > 500)
* {*
* Tlc.set(15,4095);*
* Tlc.update();*
* }*
* else*
* {*
* tlc_addFade (15, 4000, 0, 1000, 4000);
_
}*_

*/
* }*
* Serial.println();*
* delay(100);*
}
// The selectMuxPin function sets the S0, S1, and S2 pins
// accordingly, given a pin from 0-15.
void selectMuxPin(byte pin)
{
* for (int i=0; i<4; i++)*
* {*
* if (pin & (1<<i))*
_ digitalWrite(selectPins*, HIGH);
else*
digitalWrite(selectPins*, LOW);
}*_

Grumpy_Mike:
This tells you what you need:-

tlc_addFade( channel, startValue, endValue, startMillis, endMillis )

The channel number is the number of the LED you want to light.

You will have a number of the sensor that is close to the LED. If you have wired things up correctly simply transfer ( use the same number ) of the sensor number where you detect the object, into the channel you want to light. If you have not wired it up so they are the same then use an array to link the two, where the array index is the sensor number and the contents of the array is the number of light you want to activate.

No idea what you mean. I don’t know what is stopping you.

I have been able to control the LEDs through the IR.
Now I need help, instead of the leds turn off soon, how do I add this instruction to the code?

tlc_addFade (“channel”, 4000, 0, 1000, 4000);

#include "Tlc5940.h"
#include "tlc_fades.h"


#define S0 8
#define S1 6
#define S2 5
#define S3 4 
#define SIG A0


void setup(){
  Serial.begin(9600);
  
  pinMode(S0, OUTPUT); 
  pinMode(S1, OUTPUT); 
  pinMode(S2, OUTPUT); 
  pinMode(S3, OUTPUT);   

  digitalWrite(S0, LOW);
  digitalWrite(S1, LOW);
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);


  Tlc.init ();
  
  
  
}


void loop(){
tlc_updateFades();
  //Loop through and read all 16 values
  //Reports back Value at channel 6 is: 346
  for(int i = 0; i < 16; i ++){
//    Serial.print("Value at channel ");
//    Serial.print(i);
//    Serial.print(": ");
    Serial.print(readMux(i));
    Serial.print(".   ");
  }
if (readMux(15) > 500)
   {
    Tlc.set(15,4000);
    Tlc.update();
   }
  else
   {
    Tlc.set(15, 0);
    Tlc.update();
   }
   
   
 if (readMux(14) > 500)
   {
    Tlc.set(14,4000);
    Tlc.update();
   } 
    else
   {
    Tlc.set(14, 0);
    Tlc.update();
   }
  if (readMux(13) > 500)
   {
    Tlc.set(13,4000);
    Tlc.update();
   } 
    else
   {
    Tlc.set(13, 0);
    Tlc.update();
   }

 
  Serial.println();
  delay(50);
}


int readMux(int channel){
  int controlPin[] = {S0, S1, S2, S3};

  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG);

  //return the value
  return val;
}

Now I need help, instead of the leds turn off soon, how do I add this instruction to the code?

You replace the section of code that turns on or off the led with the fade calls.

Can you help me ? I'm needing Code full the reactive led coffee table :(