MIDI code problem with writing

Hello Im making a MIDI project and I found this MIDIUSB - Arduino Reference
library that will make my arduino mega 2560 USB to send midi data my question is when I type the code

void setup() {
MidiUSB.sendMIDI(midiEventPacket_t event);
MidiUSB.flush()
}

It says an error message that MIDI USB isnt declared how should I declare it ? Im new to programing so any help would be useful :slight_smile:

error Message :

Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Adun\AppData\Local\Temp\arduino_modified_sketch_716049\sketch_feb22a.ino: In function 'void setup()':

sketch_feb22a:2: error: 'MidiUSB' was not declared in this scope

MidiUSB.sendMIDI(midiEventPacket_t event);

^

sketch_feb22a:2: error: 'midiEventPacket_t' was not declared in this scope

MidiUSB.sendMIDI(midiEventPacket_t event);

^

exit status 1
'MidiUSB' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You probably didn't include the library:

#include "MIDIUSB.h"

as shown in the example here but there's no way to know for sure because you didn't post all your code.
If you do post your code, post it in code tags.

Pete

el_supremo:
You probably didn't include the library:

#include "MIDIUSB.h"

as shown in the example here but there's no way to know for sure because you didn't post all your code.
If you do post your code, post it in code tags.

Pete

Im making a MIDI controller the controller cant make sound on its own only through a computer ...
so what kind of code should I write ? I wrote this

void setup() {
#include "MIDIUSB.h";
 MidiUSB.sendMIDI(midiEventPacket_t event);
 MidiUSB.flush();

}

and this is the error
Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Adun\AppData\Local\Temp\arduino_modified_sketch_556792\sketch_feb22a.ino:2:22: fatal error: MIDIUSB.h: No such file or directory

#include "MIDIUSB.h";

^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Use the arduino library manager to install the midiusb library.
And the include of MIDIUSB.h should be at the beginning of the sketch, not in the setup() function.

Pete

el_supremo:
Use the arduino library manager to install the midiusb library.
And the include of MIDIUSB.h should be at the beginning of the sketch, not in the setup() function.

Pete

This is my code and I got another error T_T

/Code
#include "MIDIUSB.h"
void setup() {
MidiUSB.sendMIDI(midiEventPacket_t event);
MidiUSB.flush()
}
/Code

ERROR :

Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from C:\Users\Adun\AppData\Local\Temp\arduino_modified_sketch_450401\sketch_feb26a.ino:1:0:

C:\Users\Adun\Documents\Arduino\libraries\MIDIUSB\src/MIDIUSB.h:18:2: error: #error MIDIUSB can only be used with an USB MCU.

#error MIDIUSB can only be used with an USB MCU.

^

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

what is a USB MCU ? Does mega 2560 not have it ? Or do I need to activate it ? thanks for the help :slight_smile:

The Arduino Mega doesn't support MIDI USB natively.
MIDI Controller library

Pieter

PieterP:
The Arduino Mega doesn't support MIDI USB natively.
MIDI Controller library

Pieter

hello thanks for the link I but I have a question about PJRC Encoder library do I need to install it when I dont use jogwheels ? I use only rotary potentiometers and linear pots.

Yes, unless you uncomment RotaryEncoder.h from the MIDI_Controller.h file and delete RotaryEncoder.cpp and RotaryEncoder.h.