Since there's a ton of arduino drum kit but it doesn't include hihat control. i use two 4051 as an analog mux to give me more inputs.
i want to control my hihat using a pot like microdrum did. please help me in coding the hihat and th choke for cymbals. thank you.
here is the schematic of the microdrum
and the code
//36bass
//38snare
//45ride
//52hats
//71toms
unsigned char PadNote[16] = {47,18,32,39,43,13,45,17,38,127,22,71,36,45,52,77};
unsigned char status;
int PadCutOff[16] = {400,400,400,380,400,400,500,600,350,400,450,400,400,500,600,600};
int MaxPlayTime[16] = {25,25,25,25,25,25,25,25,10,40,25,40,25,25,10,10};
#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);
}