
int nNotes = 12;
int notes[] = {64, 66, 71, 73, 74, 66, 64, 73, 71, 66, 74, 73};
int duration1 = 170;
int duration2 = 167;
int index1 = 11;
int index2 = 11;
int delay1 = 0;
int delay2 = 0;
#define MIDI_ON 144
// midi2Pd function declaration with optional arguments
void midi2Pd( int cmd, int data1 = -1, int data2 = -1 );
void setup()
{
Serial.begin( 115200 ); // set the baud rate
}
void loop()
{
if ( delay1 == 0 ) {
midi2Pd( MIDI_ON, notes[index1], 0 ); // turn off previous note
index1 += 1;
if (index1 >= nNotes) index1 = 0;
midi2Pd( MIDI_ON, notes[index1], 64 ); // turn on next note
delay1 = duration1;
}
if ( delay2 == 0 ) {
midi2Pd( MIDI_ON, notes[index2], 0 ); // turn off previous note
index2 += 1;
if (index2 >= nNotes) index2 = 0;
midi2Pd( MIDI_ON, notes[index2], 64 ); // turn on next note
delay2 = duration2;
}
int minDelay = min( delay1, delay2 );
delay1 = delay1 - minDelay;
delay2 = delay2 - minDelay;
delay( minDelay );
}
// Send a MIDI message of 1 to 3 ``bytes'' (without checking values)
void midi2Pd( int cmd, int data1, int data2 )
{
Serial.print( cmd );
if ( data1 >= 0 ) {
Serial.print(' ');
Serial.print( data1 );
}
if ( data2 >= 0 ) {
Serial.print(' ');
Serial.print( data2 );
}
Serial.println();
}
|
| ©2004-2026 McGill University. All Rights Reserved. Maintained by Gary P. Scavone. |