hi, me again. i found an awesome code from Greg Kennedy on the fourm. it is a midi to arduino sketch, but it only does one channel. im trying to get it to do 3.
what i changed:
added
// MIDI channel to answer to, 0x00 - 0x0F
#define myChannel 0x00
#define myChannel1 0x01
#define myChannel2 0x02
#define tonePin2 11
#define tonePin3 12
//setup: declaring iputs and outputs and begin serial
pinMode(tonePin2,OUTPUT);
pinMode(tonePin3,OUTPUT);
what im trying to figure out
void loop () {
static byte note;
static byte lastCommand = MIDI_IGNORE;
static byte state;
static byte lastByte;
while (Serial.available()) {
// read the incoming byte:
byte incomingByte = Serial.read();
// Command byte?
if (incomingByte & 0b10000000) {
if (respondAllChannels ||
(incomingByte & 0x0F) == myChannel)
(incomingByte & 0x0F) == myChannel2)
(incomingByte & 0x0F) == myChannel3)
{
lastCommand = incomingByte & 0xF0;
} else { // Not our channel. Ignore command.
lastCommand = MIDI_IGNORE;
}
state = MIDI_STATE_BYTE1; // Reset our state to byte1.
} else if (state == MIDI_STATE_BYTE1) { // process first data byte
if ( lastCommand==MIDI_CMD_NOTE_OFF )
{ // if we received a "note off", make sure that is what is currently playing
if (note == incomingByte) noTone(tonePin);
state = MIDI_STATE_BYTE2; // expect to receive a velocity byte
} else if ( lastCommand == MIDI_CMD_NOTE_ON ){ // if we received a "note on", we wait for the note (databyte)
lastByte=incomingByte; // save the current note
state = MIDI_STATE_BYTE2; // expect to receive a velocity byte
}
// implement whatever further commands you want here
} else { // process second data byte
if (lastCommand == MIDI_CMD_NOTE_ON) {
if (incomingByte != 0) {
note = lastByte;
tone(tonePin,(unsigned int)pgm_read_word(&frequency[note]));
} else if (note == lastByte) {
noTone(tonePin);
}
}
state = MIDI_STATE_BYTE1; // message data complete
// This should be changed for SysEx
}
}
}
the goal: making my arduino play barenaked ladies