This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino


This example demonstrates the use of LED bar graphs that respond to incoming MIDI note events. The LEDs are driven by a 74HC595 (or equivalent) shift register.

AVR, AVR USB, Teensy 3.x, ESP32


Connect eight LEDs (and series resistors) between the outputs of the shift register and ground.

Remember to connect the enable pin of the shift register to ground and the master reset pin to Vcc in order to enable it.


If a MIDI Note On event for note 0x3C (C4 or middle C) is sent, the LED bar display is turned on, the higher the velocity (the harder you press the key), the more LEDs will turn on.


Route the MIDI output of a MIDI keyboard or from an audio workstation to the Arduino's MIDI input.

Written by PieterP, 2019-11-25

// Include the library
// Instantiate a MIDI Interface to use
// Instantiate a shift register as output for the LEDs
10, // Latch pin (ST_CP)
MSBFIRST, // Byte order
using namespace MIDI_Notes;
// Create a LED bar driver that listens for MIDI Note C4 that drives
// the LEDs connected to the eight input pins of the shift register
NoteLEDBar<8> leds = { sreg.pins(), note(C, 4) };
// Initialize the Control Surface
void setup() {
// Update the Control Surface
void loop() {
* Extra
* =====
* 1. The exact same approach can be used to make a LED bar graph that shows
* the value of a Control Change input.
* In that case, use CCLEDBar instead of NoteLEDBar.
* 2. You can use any type of pins for the LEDs, and in any combination.
* For example, if you want to use the normal Arduino pins 2-9:
* NoteLEDBar<8> leds = {
* {{2, 3, 4, 5, 6, 7, 8, 9}},
* note(C, 4),
* };
* Note the use of double braces for the list of numbers.
* You can even mix and match pins of different types:
* NoteLEDBar<8> leds = {
* {{2, 3, 4, 5, 6, 7,, }},
* note(C, 4),
* };
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
Definition: SPIShiftRegisterOut.hpp:23
The main header file that includes all Control-Surface header files.
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
Definition: Control_Surface_Class.cpp:171
constexpr int8_t note(int8_t note, int8_t numOctave)
Get the MIDI note in the given octave.
Definition: Notes.hpp:35
void begin()
Initialize the Control_Surface.
Definition: Control_Surface_Class.cpp:22
Class that listens for Note events and displays the velocity on an LED Bar Graph.
Definition: NoteCCRangeLEDBar.hpp:51
constexpr int8_t C
Definition: Notes.hpp:18
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over the USB CDC...
Definition: DebugMIDI_Interface.hpp:114
MIDI note names.
Definition: Notes.hpp:16
Array< pin_t, N > pins() const
Get an array containing all pins of the element.
Definition: StaticSizeExtendedIOElement.hpp:24
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
Definition: Control_Surface_Class.cpp:45