I am Using an Arduino Mega 2560, i am attempting to make and electronic drum kit.
i am using Piezo sensors connected to the analog pins that will determine the note (which pad is hit) and the velocity of the hit.
All of this will be sent to my computer via usb as serial data.
Here is a sketch I made, its very simple, I just need someone to go through it and check if everything is fine and if it works.
code is made for Hihat... Kick... Snare... Crash... Tom1... Tom2... Tom3... and Ride.
please reply and tell me what you think!
int Nkick = 36; // Kick Midi Note //
int Nsnare = 40; // Snare Midi Note//
int Ncrash = 77; // Crash Midi Note//
int ch = 51; // Closed HAT Note// These are the midi notes that are
int oh = 56; // Open HAT Note // sent to your program (change them
int Nride = 60; // Ride Midi Note // depending on your program.
int Ntom1 = 71; // Tom1 Midi Note //
int Ntom2 = 69; // Tom2 Midi Note //
int Ntom3 = 67; // Tom3 Midi Note //
void setup(){
Serial.begin(57600);
}
void loop(){
int thresh = 100; // Threshold before sound is triggered
int Hihat = analogRead(A0); // Value from Pin // Hihat //
int Switch = analogRead(A1); // Read from switch // Pad + //
int Vhihat = ((Hihat - 7)/8); // Velocity value // Switch//
delay(10);
int snareA2 = analogRead(A2); // Value from Pin // Snare //
int Vsnare = ((snareA2 - 7)/8); // Velocity value // Pad //
delay(10);
int kickA3 = analogRead(A3); // Value from Pin // Kick //
int Vkick = ((kickA3 - 7)/8); // Velocity value // Pad //
delay(10);
int crashA4 = analogRead(A4); // Value from Pin // Crash //
int Vcrash = ((crashA4 - 7)/8); // Velocity value // Pad //
delay(10);
int rideA5 = analogRead(A5); // Value from Pin // Ride //
int Vride = ((rideA5 - 7)/8); // Velocity value // Pad //
delay(10);
int tom1A6 = analogRead(A6); // Value from Pin // Tom1 //
int Vtom1 = ((tom1A6 - 7)/8); // Velocity value // Pad //
delay(10);
int tom2A7 = analogRead(A7); // Value from Pin // Tom2 //
int Vtom2 = ((tom2A7 - 7)/8); // Velocity value // Pad //
delay(10);
int tom3A8 = analogRead(A8); // Value from Pin // Tom3 //
int Vtom3 = ((tom3A8 - 7)/8); // Velocity value // Pad //
////////////////////////////////////////////////////////////////////////////
// Testing if pad is being hit... if yes then it will send a Midi Message //
////////////////////////////////////////////////////////////////////////////
if((Switch == 1023) && (Hihat > thresh))
{
MIDI_send(144,oh,Vhihat);
MIDI_send(128,oh,0);
}
else if(Switch = 0 && Hihat > thresh);
{
MIDI_send(144,oh,Vhihat);
MIDI_send(128,oh,0);
}
if (snareA2 > thresh){
MIDI_send(144,Nsnare,Vsnare);
MIDI_send(128,Nsnare,0);
}
if (kickA3 > thresh){
MIDI_send(144,Nkick,Vkick);
MIDI_send(128,Nkick,0);
}
if (crashA4 > thresh){
MIDI_send(144,Ncrash,Vcrash);
MIDI_send(128,Ncrash,0);
}
if (rideA5 > thresh){
MIDI_send(144,Nride,Vride);
MIDI_send(128,Nride,0);
}
if (tom1A6 > thresh){
MIDI_send(144,Ntom1,Vtom1);
MIDI_send(128,Ntom1,0);
}
if (tom2A7 > thresh){
MIDI_send(144,Ntom2,Vtom2);
MIDI_send(128,Ntom2,0);
}
if (tom3A8 > thresh){
MIDI_send(144,Ntom3,Vtom3);
MIDI_send(128,Ntom3,0);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
// Sending the Midi Message to your computer -> Hairless Midi -> Vst (Addictive Drums) //
/////////////////////////////////////////////////////////////////////////////////////////
void MIDI_send(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) {
Serial.write(MESSAGE);
Serial.write(PITCH);
Serial.write(VELOCITY);
}