[ASK] CC with TCRT5000 and IC CD4051 for Hihat Controller

hello, I am very new to arduino but I wanted to make my own project … especially for Arduino Drum.
I have 6 months working on this project… I think all run normally, but I find problem of the hi-hat controller when I uses sensors tcrt5000…

I could not find a solution in another forum and I would like to ask here …
what I want is Arduino sends CC (Control Change) to the Drum Software (addictive drum 2) using TCRT5000 …

I give a schematic and sketch that I use …

unsigned char PadNote[16] = {69,99,3,36,46,6,79,0,50,10,11,12,13,60,38,71};        
unsigned char status;
int PadCutOff[16] = {200,200,200,100,200,200,200,200,200,200,200,300,200,200,200,200};   
int MaxPlayTime[16] = {35,25,25,25,25,25,25,25,25,40,25,40,25,25,25,25};        
#define  midichannel 0;                 
boolean activePad[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};      
int PinPlayTime[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};             
boolean VelocityFlag  = true;            
int analogPin[2] = {A0,A1}; 
int pin = 0;
int hitavg = 0;
int pad = 0;
int r0 = 0;
int r1 = 0;
int r2 = 0;
int count = 0;
int multiplex1[8];
int multiplex2[8];


//*******************************************************************************************************************
// Setup			
//*******************************************************************************************************************

void setup() 
{
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  Serial.begin(115200);                                  // connect to the serial port 115200
}

//*******************************************************************************************************************
// Main Program			
//*******************************************************************************************************************

void loop(){

  readSensors(0);
  readSensors(1);
  checkSensors(0);
  checkSensors(1);
}

void readSensors (int analogPin) {
  for(count=0; count <= 7; count++)
  {
    r2 = bitRead(count,0);
    r1 = bitRead(count,1);
    r0 = bitRead(count,2);
    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
    if(analogPin==0) {
    multiplex1[count] = analogRead(analogPin);
  }
  else if(analogPin==1) {
    multiplex2[count] = analogRead(analogPin);
  }
  }
}
  
void checkSensors (int analogPin) {
  for(int pin=0; pin <=7; pin++) {
    if(analogPin==0) {
    hitavg = multiplex1[pin];
    pad=pin;
    }
    else if(analogPin==1) {
    hitavg = multiplex2[pin];
    pad=pin+8;
    }
   
    if((hitavg > PadCutOff[pad])) {
      if((activePad[pad] == false)) {
        if(VelocityFlag == true) {
          hitavg = (hitavg / 8) -1;
        }
        else {
          hitavg = 127;
        }
        MIDI_TX(144,PadNote[pad],hitavg);
        PinPlayTime[pad] = 0;
        activePad[pad] = true;
      }
      else {
        PinPlayTime[pad] = PinPlayTime[pad] + 1;
      }
    }
    else if((activePad[pad] == true)) {
      PinPlayTime[pad] = PinPlayTime[pad] + 1;
      if(PinPlayTime[pad] > MaxPlayTime[pad]) {
       activePad[pad] = false;
       MIDI_TX(128,PadNote[pad],0);
      }
    }
  }
}

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) {
  status = MESSAGE + midichannel;
  Serial.write(status);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
}

As you can see in the schematic, HCC (hihat control change) is P4 connect to the CD4051 when seen in Sketch … pins are connected with HCC is no 99…

I’m sorry if my english is very bad …

so… i found the other projects similliar… but unfortunately they use diffirent sensor (QTRSensors) and diffirent multiplexer they call YAAMIDRUM, i have attached the code, I can’t write here, too long…so I think my goal is not impossible to use TCRT5000 for control hihat…

but i still don’t know what i must supposed to do… :frowning:

YAAMIDrum1_2.ino (19.6 KB)

I just write some code… and it works, at least it detect my infrared sensor…
but they sent CC number 36 with max value 42 and it roll very quickly… (i see in the hairless midi serial converter) I want they sent CC number 4 and it will roll (in the hairless) if i move the sensor…(hope you guys can understand what i mean…)

and here some code i’ve change…

void loop(){

  readSensors(0);
  readSensors(1);
  checkSensors(0);
  checkSensors(1);
}
void readSensors (int analogPin) {    //mulai baca Multiplex 4051
  for(count=0; count <= 7; count++)
  {
    r2 = bitRead(count,0);
    r1 = bitRead(count,1);
    r0 = bitRead(count,2);
    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
    if(analogPin==0) {
    multiplex1[count] = analogRead(analogPin);
  }
  else if(analogPin==1) {
    multiplex2[count] = analogRead(analogPin);
  }
  }
}
  
void checkSensors (int analogPin) {
  for(int pin=0; pin <=7; pin++) {
    if(analogPin==0) {
    hitavg = multiplex1[pin];
    pad=pin;
    }
    else if(analogPin==1) {
    hitavg = multiplex2[pin];
    pad=pin+8;
    }
   
    if((hitavg > PadCutOff[pad])) {
      if((activePad[pad] == false)) {
        if(VelocityFlag == true) {
         /// hitavg = (hitavg / 8) -1;
          hitavg = 127 / ((1023 - PadCutOff[pad]) / (hitavg - PadCutOff[pad]));
        }
        else {
          hitavg = 127;
        }
        if (analogPin==0 && PadNote[pad]){
          MIDI_TX(176,PadNote[2],hitavg); //hihat pedal
          int cc = 4;
          PinPlayTime[2] = 0;
          activePad[2] = true;
          }
            else{
                 MIDI_TX(144,PadNote[pad],hitavg);
                 PinPlayTime[pad] = 0;
                 activePad[pad] = true;
                }
              }
      else {
        PinPlayTime[pad] = PinPlayTime[pad] + 1;
      }
    }
    else if((activePad[pad] == true)) {
      PinPlayTime[pad] = PinPlayTime[pad] + 1;
      if(PinPlayTime[pad] > MaxPlayTime[pad]) {
       activePad[pad] = false;
       MIDI_TX(128,PadNote[pad],0);
      }
    }
  }
}

now i try add

unsigned char SensorType[16] = {144,176,144,144,144,144,144,144,144,144,144,144,144,144,144,144};
unsigned char PadNote[16] = {47,2,32,43,43,13,45,17,8,36,38,44,0,19,38,57};

and also change some code in loop :

if (SensorType[pin]==176 && PadNote[1]){//176 sensor tcrt5000
          MIDI_TX(176,PadNote[1],hitavg);
          }

and... it's work!!!! but I did not test the all instrument yet... but it's work!!!!

I am also new to this

Please share your edited code for TCRT-5000 sensor so that I can build one for myself.

Thanks in Advance