So i wanted to try out a midi piano project i found but, was having some problems compiling.
I have the IDE installed along with the standard arduino midi library 4.2 installed as well. Restarted my computer, edited the code and got these errors while trying to compile:
Arduino: 1.6.5 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Build options changed, rebuilding all
midi:5: error: #include expects "FILENAME" or <FILENAME>
midi:6: error: expected constructor, destructor, or type conversion before ';' token
midi.ino: In function 'void setup()':
midi:40: error: 'MIDI' was not declared in this scope
midi:40: error: 'MIDI_CHANNEL_OMNI' was not declared in this scope
midi.ino: In function 'void loop()':
midi:65: error: 'MIDI' was not declared in this scope
midi:84: error: 'MIDI' was not declared in this scope
#include expects "FILENAME" or <FILENAME>
I just have the 3 inputs so adjusted it according to what the instructions say on that site. Is there a problem with the coding, midi library or something else? I can upload sample sketches no problem, just not this one. Here is the code i edited for use on my project:
/*
MIDI Toy Piano Hack Code
*/
#include
MIDI_CREATE_DEFAULT_INSTANCE();
//========================================================================================
//Values you may need to change
//Set this value to the number of keys/piezos you are using
const int NUM_OF_KEYS = 3;
//Adjust this value to change the sensitivity of the piezos
const int THRESHOLD = 5;
//Set this value to the number of microseconds you want each MIDI note to last for
const int NOTE_LENGTH = 50;
//Adjust this value to set the range of MIDI note velocity values
const int VEL_SENSE_VAL = 2;
//Change this number to set what MIDI channel the MIDI notes are set to
const int midiChan = 1;
//Change these numbers to set what MIDI note number each key/piezo will send.
//Also make sure that the total number of numbers here matches the value of NUM_OF_KEYS
const int midiNote[NUM_OF_KEYS] = {86, 84, 83};
//Change these values to set which analog input pins you are using
//Also make sure that the total number of values here matches the value of NUM_OF_KEYS
const int triggerSensor[NUM_OF_KEYS] = {A0, A1, A2};
//=======================================================================================
//Variables for storing certain values
int triggerVal[NUM_OF_KEYS] = {0};
bool noteIsOn[NUM_OF_KEYS] = {false};
int midiNoteTime[NUM_OF_KEYS] = {0};
int midiVelocityVal[NUM_OF_KEYS] = {0};
void setup()
{
MIDI.begin(MIDI_CHANNEL_OMNI);
}
void loop()
{
//repeat the below code for each anaolog input/piezo sensor
for (int count; count < NUM_OF_KEYS; count++)
{
//read the piezo value
triggerVal[count] = analogRead(triggerSensor[count]);
//if the value is over the threshold and there isn't currently a note on for this piezo
if (triggerVal[count] > THRESHOLD && noteIsOn[count] == false)
{
//get a velocity value based on the value
midiVelocityVal[count] = triggerVal[count] * (127.0/1023.0);
//increase sensitivity
midiVelocityVal[count] *= VEL_SENSE_VAL;
//make sure we don't go out of range
if (midiVelocityVal[count] > 127)
midiVelocityVal[count] = 127;
//send a MIDI note-on message
MIDI.sendNoteOn (midiNote[count], midiVelocityVal[count], midiChan);
//flag that the note is on
noteIsOn[count] = true;
//start a timer for the note to be on for
midiNoteTime[count] = NOTE_LENGTH;
}
//if the note is currently on
if (noteIsOn[count] == true)
{
//reduce the time value by 1
midiNoteTime[count]--;
//if time value equals 0
if (midiNoteTime[count] == 0)
{
//turn off the note
MIDI.sendNoteOff (midiNote[count], 0, midiChan);
noteIsOn[count] = false;
}
}
}
//pause the loop
delay(1);
}