digital outputs

Connect the Anode (+) or longer leg of the LED to one of your digital output pins — in this case Pin 9. Connect the shorter, or cathode, leg to ground through a 220Ω resistor (red red brown gold).

If you play the MIDI note associated with pin 9, the pin is turned on, or set to HIGH, and will send 3.3v through the LED and the resistor, completing the circuit to ground. Your LED should turn on! Let’s look at the code…

// Instantiate an array of NoteLED objects that receive midi note events from the 
// computer to turn LEDs on and off on the microcontroller 
NoteLED leds[]{ 
{9, MIDI_Notes::E(4)}, // pin 9: LED output (midi note E4 or 64) 
};

Create a NoteLED object and set up an array, leds[]. The array lets you easily add more leds if you want. Next specify the pin (9) and the MIDI note that the pin responds to, note E4.

You can use a similar setup to drive a small vibration motor. Connect one leg of the motor (it really doesn’t matter which leg in this case) to power (red) and the other leg to ground through a 10K resistor. You won’t be able to control the speed of the motor, but you’ll be able to turn it on and off from your computer by sending a MIDI note. A better way to connect a motor uses a new component called.a transistor.