MIDIライブラリを追加する
https://playground.arduino.cc/Main/MIDILibrary/
ここが詳しい
https://qiita.com/yudai220/items/3bde9461f282d56d1ac2
#include <MIDI.h>
// Created and binds the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();
// 初期化===========================================================
// LED Bright level
int cc_value = 0;
// PWM OUT
const int led_pin = 9;
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI); // 全MIDI CH
MIDI.turnThruOff();
}
void loop() {
uint8_t data1,data2;
if (MIDI.read()) {
switch(MIDI.getType()) {
case midi::ControlChange: // Breath(CC#2)
data1 = MIDI.getData1(); // CCナンバーが入る(2バイト目)
data2 = MIDI.getData2(); // CCの値が入る(3バイト目)
// CC#2 check
if (data1 = 2) {
cc_value = data2 * 2; // BreathはCC#2
}
//ここにCC#2のcc_valueを使った処理を記述する
//analogWrite( led_pin, cc_value );
break;
/* 他にも取り込みたいデータがあれば列記する(ノートナンバーとか)
case midi::NoteOn: // Key down
data1 = MIDI.getData1(); // Note No.
data2 = MIDI.getData2(); // Velocity
break;
case midi::NoteOff: // Key up
data1 = MIDI.getData1(); // Note No.
data2 = MIDI.getData2(); // Velocity
break;
*/
}
}
}