SpikenzieLabs Drumkit
SpikenzieLabs offers a pre-written code that looks like this:
/
// DESCRIPTION:
// Arduino analog input used to sense piezo drum hits then sent serialy to processing.
//*******************************************************************************************************************
// User settable variables
//*******************************************************************************************************************
unsigned char PadNote[6] = {52,16,66,63,40,65}; // MIDI notes from 0 to 127 (Mid C = 60)
int PadCutOff[6] = {600,600,600,600,600,600}; // Minimum Analog value to cause a drum hit
int MaxPlayTime[6] = {90,90,90,90,90,90}; // Cycles before a 2nd hit is allowed
#define midichannel 0; // MIDI channel from 0 to 15 (+1 in “real world”)
boolean VelocityFlag = true; // Velocity ON (true) or OFF (false)
//*******************************************************************************************************************
// Internal Use Variables
//*******************************************************************************************************************
boolean activePad[6] = {0,0,0,0,0,0}; // Array of flags of pad currently playing
int PinPlayTime[6] = {0,0,0,0,0,0}; // Counter since pad started to play
unsigned char status;
int pin = 0;
int hitavg = 0;
//*******************************************************************************************************************
// Setup
//*******************************************************************************************************************
void setup()
{
Serial.begin(57600); // connect to the serial port 115200
}
//*******************************************************************************************************************
// Main Program
//*******************************************************************************************************************
void loop()
{
for(int pin=0; pin < 6; pin++)
{
hitavg = analogRead(pin); // read the input pin
if((hitavg > PadCutOff[pin]))
{
if((activePad[pin] == false))
{
if(VelocityFlag == true)
{
// hitavg = 127 / ((1023 – PadCutOff[pin]) / (hitavg – PadCutOff[pin])); // With full range (Too sensitive ?)
hitavg = (hitavg / 8) -1 ; // Upper range
}
else
{
hitavg = 127;
}
MIDI_TX(144,PadNote[pin],hitavg);
PinPlayTime[pin] = 0;
activePad[pin] = true;
}
else
{
PinPlayTime[pin] = PinPlayTime[pin] + 1;
}
}
else if((activePad[pin] == true))
{
PinPlayTime[pin] = PinPlayTime[pin] + 1;
if(PinPlayTime[pin] > MaxPlayTime[pin])
{
activePad[pin] = false;
MIDI_TX(128,PadNote[pin],127);
}
}
}
}
//*******************************************************************************************************************
// Transmit MIDI Message
//*******************************************************************************************************************
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
status = MESSAGE + midichannel;
Serial.print(status);
Serial.print(PITCH);
Serial.print(VELOCITY);
}
}
}
Here is the basic drum bit. Now my objective is to add the same of LEDs as there are Pads. (one per, in this example a total of 7). I have chosen the PCF8575C from Sparkfun Electronics because i'll need 16+ led in the end project and this breakout board has 16. So upon a NoteON event the corresponding led should go HIGH on NoteOFF the led should be OFF and stay OFF until a note is ON again.
Area in the Drum Kit sketch where the user can tune the drum kit for their set-up.
Here is an explanation of the different areas where you can tune your drum kit.
PadNote: These are the MIDI notes that will be played when a drum pad is triggered. They range from 0 to 127, where middle C is the number 60. Do not use a value above 127.
PadCutOff: The Arduino reads analog values as a number from 0 to 1023. When you hit a drum pad the piezo creates a voltage spike and ripple. We are reading the value of this voltage spike. The padCutOff is the minimum value of this spike that we will accept as a drum hit. You can set it higher or lower. Lower will make more false triggers, but easier to make drum hits if your pads are thick. Higher will require you to hit the pads harder to make them sound, but you will get less false triggers from hitting a nearby pad if they are on the same surface.
MaxPlayTime: Is a delay based on the number of times the main loop of the program runs through. This delay is intended to keep the kit from sounding multiple hits for one drum hit, since the Arduino is fast enough to read the same voltage spike a few times. If you are getting two hits etc, when you hit the drum only once, increase this number if there is too large a delay when you play a drum roll, then decrease this number.
midichannel: Is simply the MIDI channel that will be send in the MIDI message.
VelocityFlag: Is a true or false setting to use velocity or not. Velocity is the value of how hard you hit the drum pad. A higher velocity would produce a louder drum sound.
My understanding is that PadcutOff is the On/OFF point for NoteOn/NoteOFF so at those points I need to trigger LED_on /Led_off on i2c.
again
Midi_footsteps is an exact example to what I'm trying to accomplish, as well as how my port expander is wired.
Here is how Mike did it http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps_files/Footsteps%20Software.zip it's homepage http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
Help !