Ch1(0x00)にプログラムチェンジ(0xc0)のコマンドを送ると、第1パラメータにセットした回数分のパルスをA7ピンに発生させるサンプルです。
#include <MIDI.h>
#define LED A7
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); // use serial-1(TX1/RX1)
void BlinkLed(byte num) // Basic blink function
{
for (byte i=0;i<num;i++)
{
digitalWrite(LED,HIGH); // Increase the width of the pulse
digitalWrite(LED,HIGH); // by 4 times
digitalWrite(LED,HIGH);
digitalWrite(LED,HIGH);
digitalWrite(LED,LOW);
}
}
// -----------------------------------------------------------------------------
void setup()
{
pinMode(LED, OUTPUT);
MIDI.begin(1); // Launch MIDI, by default listening to channel 1.
BlinkLed(1);
}
void loop()
{
if (MIDI.read()) // Is there a MIDI message incoming ?
{
switch(MIDI.getType()) // Get the type of the message we caught
{
case midi::ProgramChange: // If it is a Program Change (0xCn),
BlinkLed(MIDI.getData1()); // blink the LED a number of times
// correponding to the program number
// (0 to 127, it can last a while..)
break;
// See the online reference for other message types
default:
break;
}
}
}