Custom-Note-LED-Input-Element-Callback-FastLED
This example demonstrates how to attach custom callbacks to Note or Control Change MIDI Input Elements.
- Boards: 🛈
- AVR, AVR USB, Nano 33 IoT, Teensy 3.x, ESP32
Connections
- Pin 2: The data pin of a Neopixel LED strip with (at least) 8 LEDs
Behavior
If a MIDI Note On event for note 0x3C (C4 or middle C) is sent, its velocity value sets the red value of the first LED, note 0x3D controls the green value of the first LED, note 0x3E controls the blue value of the first LED, note 0x3F controls the red value of the second LED, 0x40 controls the green value of the second LED, etc.
Mapping
Route the MIDI output of a MIDI keyboard to the Arduino's MIDI input. Then play some notes in the two octaves above middle C.
Alternatively, map it in you DAW, for example, in VirtualDJ:
<color notered="0x3C" notegreen="0x3D" noteblue="0x3E" ... />
Written by PieterP, 2020-03-12
https://github.com/tttapa/Control-Surface
#include <FastLED.h>
template <uint8_t RangeLen>
TwoByteRangeMIDIMatcher> {
public:
ledcolors(ledcolors) {}
}
void updateLED(uint8_t index, uint8_t value) {
uint8_t ledIndex = index / 3;
uint8_t colorIndex = index % 3;
ledcolors[ledIndex][colorIndex] = value;
dirty = true;
}
bool getDirty() const { return dirty; }
void clearDirty() { dirty = false; }
private:
CRGB *ledcolors;
bool dirty = true;
};
Array<CRGB, 8> leds {};
constexpr uint8_t ledpin = 2;
CustomNoteLED<leds.length * 3> midiled {leds.data,
MIDI_Notes::C[4]};
void setup() {
FastLED.addLeds<NEOPIXEL, ledpin>(leds.data, leds.length);
FastLED.setCorrection(TypicalPixelString);
FastLED.setBrightness(128);
}
void loop() {
if (midiled.getDirty()) {
FastLED.show();
midiled.clearDirty();
}
}
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.
@ NoteOn
Note On Channel Voice message (3B).
void begin()
Initialize the Control_Surface.
void loop()
Update all MIDI elements, send MIDI events and read MIDI input.
A type-safe utility class for saving a MIDI address consisting of a 7-bit address,...
A class for MIDI interfaces sending MIDI messages over a USB MIDI connection.
Matcher for MIDI messages with 2 data bytes, such as Note On/Off, Control Change, Key Pressure (but n...