This simple MIDI sequencer is based on the simple Arduino tone sequencer sketch. Like that sketch, it stores a musical sequence in a two dimensional array. Each row in the array represents either a note or a rest. The first column of the array is the note pitch or REST sentinel value. The second column in the array is the note/rest duration.
The loop function steps through the rows of the array and plays each note. The loop also handles duration. The top of the loop is a one millisecond delay. The loop counts down the note (or rest) duration. When the count hits zero, the loop moves on to the next note (or rest) in the array. When the end of the array is reached, selection wraps around to the beginning of the array.
There are three source code files:
Although the actual pitch values are different (MIDI note numbers vs. tone frequencies), the note names are the same as the note names in the simple Arduino tone sequence sketch. Thus, the two sketches can play the same musical sequences, i.e., the source code initializing the array is the same.
The simple MIDI sequencer sketch is a good test for 5-pin MIDI output. For example, you may have built my basic MIDI interface and would like to test your work. The sequencer sends MIDI note on and note off messages. Attach a MIDI sound source to your Arduino, run this sketch, and you should definitely hear something. If you don’t hear anything, check your connections and make sure that the MIDI sound generator is listening to MIDI channel 1.