part 3 of my code
[code]
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI);
//Serial.begin(31250);
pinMode(MIDI_ENABLE, OUTPUT); // sets the digital pin as output
digitalWrite(MIDI_ENABLE, HIGH);
// MIDI.turnThruOff();
MIDI.setHandleNoteOn(HandleNoteOn);
MIDI.sendProgramChange(P,10);
// MIDI.setHandleClock ( HandleClock );
//MIDIfile & SD card setups
// Initialise SD
if (!SD.begin(chipSelect, SPI_HALF_SPEED))SD.initErrorHalt();
Serial.println("begin success");
SD.begin(chipSelect, SPI_HALF_SPEED);
// Initialise MIDIFile
SMF.begin(&SD);
SMF.setMidiHandler(midiCallback);
SMF.setSysexHandler(sysexCallback);
}
void Sync(){
unsigned long currentMillis = millis();
if(currentMillis - prevmillis > interval) {
// save the last time.
prevmillis = currentMillis;
MIDI.sendRealTime(Clock);
}
}
void loop () {
int err = -1;
SMF.setFilename("SCALE.MID");
SMF.load(); //lost sync at this point.
err=SMF.load(); //try to print the load result
SMF.setTempo(bpm);
if (err != -1)
{
DEBUG("\nSMF load Error ");
DEBUG(err);
//digitalWrite(SMF_ERROR_LED, HIGH);
// delay(WAIT_DELAY);
}
else
{
while (!SMF.isEOF())
{
if (SMF.getNextEvent());
}
// done with this one
SMF.close();
}
MIDI.read();
Sync();
}
[/code]