Go Down

Topic: **PLEASE HELP** Code won't verify/compile (Read 1 time) previous topic - next topic

rorycowieson

Hi, I'm completely new to arduino so really don't know much about how to code or anything. I've been following a tutorial to turn an old toy piano (not digital) into a MIDI controller using Piezos. I'll put a link to the tutorial below.

https://ask.audio/articles/turning-a-vintage-toy-piano-into-a-midi-controller-using-arduino


When I try and compile the sketch I get the following error message -

Code: [Select]

Build options changed, rebuilding all
/var/folders/dj/f6lqd1yn4kv0w3vffz0ds0940000gn/T/arduino_modified_sketch_439290/AnalogInput.ino:5:18: fatal error: MIDI.h: No such file or directory
 #include <MIDI.h>
                  ^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.



Here's the code I'm using -

Code: [Select]
/*
MIDI Toy Piano Hack Code
*/

#include <MIDI.h>
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 = 16;
//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, 81, 79, 77, 76, 74, 72, 71, 69, 67, 65, 64, 62, 60};

//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, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};

//=======================================================================================

//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);
}
     

septillion

MIDI isn't a default library. Did you download it?
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

pert

#2
Apr 23, 2016, 12:53 pm Last Edit: Apr 23, 2016, 12:54 pm by pert
Unfortunately the tutorial author didn't give a link to where you can download the MIDI library but I think I found the right one here in case you haven't installed it already: https://github.com/FortySevenEffects/arduino_midi_library. The second unfortunate thing is the MIDI library author did it wrong so you need to make a modification for the library to be usable:
  • Download https://github.com/FortySevenEffects/arduino_midi_library/archive/master.zip
  • Copy the folder arduino_midi_library-master from the .zip file to the {sketchbook folder}/libraries. To find your sketchbook folder location check File > Preferences > Sketchbook location.
  • Move all files from {sketchbook folder}/libraries/arduino_midi_library-master/src to {sketchbook folder}/libraries/arduino_midi_library-master.
  • Exit and reopen the Arduino IDE if it's running.

After doing that your code compiles for me. Let me know how it goes. Per

rorycowieson

Unfortunately the tutorial author didn't give a link to where you can download the MIDI library but I think I found the right one here in case you haven't installed it already: https://github.com/FortySevenEffects/arduino_midi_library. The second unfortunate thing is the MIDI library author did it wrong so you need to make a modification for the library to be usable:
  • Download https://github.com/FortySevenEffects/arduino_midi_library/archive/master.zip
  • Copy the folder arduino_midi_library-master from the .zip file to the {sketchbook folder}/libraries. To find your sketchbook folder location check File > Preferences > Sketchbook location.
  • Move all files from {sketchbook folder}/libraries/arduino_midi_library-master/src to {sketchbook folder}/libraries/arduino_midi_library-master.
  • Exit and reopen the Arduino IDE if it's running.

After doing that your code compiles for me. Let me know how it goes. Per
Thanks very much for your quick and very helpful response. I'll try that just now

Go Up