Hey guys, working on my first project on the Arduino. The device is a MIDI velocity sensitive drum trigger using Piezo elements to pick up vibrations. You know, standard stuff.
Here's what I've got thus far:
int threshold = 55; // 0-127 range, minimum threshold for note
int mx = 2; // number of input pins. Counting numbers (starting at 1)
int midiChan[] = {1, 1}; // MIDI Channel. Not used ATM
int midiNote[] = {15, 16}; // MIDI note
int midiVel[] = {0, 0}; // MIDI velocity initialization
boolean midiNoteIsOn[] = {false, false}; // Is note playing?
int anaVal[] = {0, 0}; // Store analog values here
void midiNoteOn(int note, int vel)
{
Serial.println(10000000); // MIDI note on message
Serial.println(note);
Serial.println(vel);
Serial.println("Note on!"); //for debugging
}
void midiNoteOff(int note)
{
Serial.println(10010000); // MIDI note off message
Serial.println(note);
Serial.println(00000000);
Serial.println("Note off!");
}
void setup()
{
Serial.begin(9600); //Also for debugging. Arduino IDE serial monitor can't do the needed 31250 baud
}
void loop()
{
for (int i=0; i<mx; i++) // Less than works with counting numbers.
{
anaVal[i] = analogRead(i); // Get 0-1023 value from pin
midiVel[i] = anaVal[i]/8; // Convert to MIDI-usuable 0-127 range
if (midiNoteIsOn[i] == false)
{
if (midiVel[i] >= threshold) // If no note is playing and the piezo is sending voltage
{
midiNoteOn(midiNote[i],midiVel[i]);
midiNoteIsOn[i] = true;
}
}
else
{
if (midiVel[i] < threshold) // If a note is playing and the voltage is below threshold, note off
{
midiNoteOff(midiNote[i]);
midiNoteIsOn[i] = false;
}
}
}
}
Unfortunately, in the serial monitor, I get this:
10000000
15
73
Note on!
10010000
15
0
Note off!
Is there any way to get those last two lines to display as 8-bit words? Help a newbie out, guys! Thanks.