Hey, I would really need some help with code, I found it on the internet, and I tried it it works, but for some reason just for analog input 0 and 1, I tried to add the analog pins in the code, didn't help, please some one help. (BTW piezo drums)
unsigned char PadNote[16] = {47,18,32,38,43,13,45,17,21,36,0,44,0,19,0,21};
unsigned char status;
int PadCutOff[16] = {100,100,100,200,100,100,100,100,100,350,100,350,100,100,100,100};
int MaxPlayTime[16] = {25,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);
}