Hello to all!
I'm trying to modify a piece of code that produces tones using the pitches.h library. I wish to send midi notes instead of creating tones.
Here is what I have modified so far...
//#include "pitches.h"
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// Two things need to be created: the array for the notes of the melody (in order)
// and the duration of each (think of it like sheet music in two parts)
// BOTH ARRAYS MUST BE THE SAME SIZE!
// The melody array
int melody[] = {
78, 78, 74, 71, 71, 76,
76, 76, 80, 80, 81, 83,
81, 81, 81, 76, 74, 78,
78, 78, 76, 76, 78, 76
};
// The note duration, 8 = 8th note, 4 = quarter note, etc.
int durations[] = {
8, 8, 8, 4, 4, 4,
4, 5, 8, 8, 8, 8,
8, 8, 8, 4, 4, 4,
4, 5, 8, 8, 8, 8
};
// determine the length of the arrays to use in the loop iteration
int songLength = sizeof(melody)/sizeof(melody[0]);
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}
void loop() {
// Iterate through both arrays
// Notice how the iteration variable thisNote is created in the parenthesis
// The for loop stops when it is equal to the size of the melody array
for (int thisNote = 0; thisNote < songLength; thisNote++){
// determine the duration of the notes that the computer understands
// divide 1000 by the value, so the first note lasts for 1000/8 milliseconds
int duration = 1000/ durations[thisNote];
tone(8, melody[thisNote], duration);
// pause between notes
int pause = duration * 1.3;
delay(pause);
// stop the tone
noTone(8);
}
}
I'm guessing my issue is around this segment
tone(8, melody[thisNote], duration);
Where "tone" needs to replaced with sending midi?
Any help at all will be appreciated