Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arduino script to display tempo beat using Cantabile Tempo LEDs binding
#include <Adafruit_NeoPixel.h>
#include <MIDI.h>
#define PIN_COLOR_LEDS 6
#define CC_TEMPO_LEDS 127
#define BEAT_MASK 0x0F
#define BEATS_SHIFT 4
#define BEATS_OFFSET 2
#define BEATS_MASK 0x0F
Adafruit_NeoPixel colorLeds = Adafruit_NeoPixel(8, PIN_COLOR_LEDS, NEO_GRB + NEO_KHZ800);
MIDI_CREATE_DEFAULT_INSTANCE();
// One time setup
void setup()
{
// Clear LEDs
colorLeds.begin();
colorLeds.clear();
colorLeds.show();
// Init MIDI
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages
}
void loop()
{
// Read MIDI events
while (MIDI.read())
{
// Is it the correct CC
if (MIDI.getType() == midi::ControlChange && MIDI.getData1() == CC_TEMPO_LEDS)
{
// Read the current beat number and beat count
int beats = ((MIDI.getData2() >> BEATS_SHIFT) & BEATS_MASK) + BEATS_OFFSET;
int beat = MIDI.getData2() & BEAT_MASK;
// Update LEDs
colorLeds.clear();
for (int i=0; i<beats; i++)
{
colorLeds.setPixelColor(i, i == beat ? 0x040404 : 0x000001);
}
colorLeds.show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment