This Arduino code plays MIDI music files by converting note data into control voltages (CV) that are output through pins to control synthesizers. It initializes MIDI file reading and CV output pins. In its loop, it checks for note on/off events, calculates the corresponding CV based on the note, and sends that CV to the appropriate voice pin to play the note. It then increments to the next event, looping through tracks and restarting when finished.
This Arduino code plays MIDI music files by converting note data into control voltages (CV) that are output through pins to control synthesizers. It initializes MIDI file reading and CV output pins. In its loop, it checks for note on/off events, calculates the corresponding CV based on the note, and sends that CV to the appropriate voice pin to play the note. It then increments to the next event, looping through tracks and restarting when finished.
This Arduino code plays MIDI music files by converting note data into control voltages (CV) that are output through pins to control synthesizers. It initializes MIDI file reading and CV output pins. In its loop, it checks for note on/off events, calculates the corresponding CV based on the note, and sends that CV to the appropriate voice pin to play the note. It then increments to the next event, looping through tracks and restarting when finished.
void setup() { // Open the MIDI file midi_file.read("song.mid");
// Set the CV output pins as outputs
for (int i = 0; i < numVoices; i++) { pinMode(cvPins[i], OUTPUT); } }
void loop() { static int track = 0; static int event = 0;
// Check if the event is a note ON event
if (midi_file[track][event].isNoteOn()) { // Get the note and velocity values int note = midi_file[track][event][1]; int velocity = midi_file[track][event][2];
// Calculate the CV output
float cv = (note - 21) / 127.0 * 5.0;
// Send the CV output to the corresponding voice
int voice = note % numVoices; analogWrite(cvPins[voice], cv * 255.0); } // Check if the event is a note OFF event else if (midi_file[track][event].isNoteOff()) { // Get the note value int note = midi_file[track][event][1];
// Reset the CV output for the corresponding voice
int voice = note % numVoices; analogWrite(cvPins[voice], 0); }