I am new to Arduino - built one board several years ago using someone else's code. Now trying to build a MIDI Beat Indicator that takes the MIDI out from my Drum Machine to a remote display that I can see from my organ bench. Using UNO R3 with a MIDI shield. I found the code example and with one correction it compiled. However, it isn't doing anything. Should blink the built in LED. Am I missing something?
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// Define MIDI input and LED pin
#define MIDI_IN_PIN 2 // Example: Use digital pin 2 for MIDI input
#define LED_PIN 13 // Example: Use digital pin 13 for the LED
// MIDI variables
byte midi_clock = 0xf8;
int clock_counter = 0;
bool running = false;
// Function to handle incoming MIDI clock messages
void handleClock() {
if (running) {
clock_counter++;
if (clock_counter >= 24) { // MIDI clock sends 24 pulses per quarter note
clock_counter = 0;
digitalWrite(LED_PIN, HIGH); // Turn LED on
delayMicroseconds(50); // Short pulse for visibility
digitalWrite(LED_PIN, LOW); // Turn LED off
}
}
}
// Function to handle incoming MIDI Start message
void handleStart() {
running = true;
clock_counter = 0;
}
// Function to handle incoming MIDI Stop message
void handleStop() {
running = false;
}
// Function to handle incoming MIDI Continue message
void handleContinue() {
running = true;
}
void setup() {
// Initialize MIDI
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.setHandleClock(handleClock);
MIDI.setHandleStart(handleStart);
MIDI.setHandleStop(handleStop);
MIDI.setHandleContinue(handleContinue);
// Set LED pin as output
pinMode(LED_PIN, OUTPUT);
// Optional: Set up serial communication for debugging
Serial.begin(115200);
}
void loop() {
MIDI.read(); // Check for incoming MIDI messages
}

