Hi, I'm trying to make a simple midi clock so I can synchronize one of my guitar pedal to it.
The program is not complete yet, I'm just testing to see if it works first. This code works ok at 120 bpm. The LED on my pedal is synchronized with the LED on my breadboard, but when I try a lower bpm (60), my pedal can't synchronize at all...
I know that midiclock is 24 messages per beat. When I put 60 bpm, I can see with MIDI-OX that it takes 1 sec to have 24 messages.
The pedal works really well when I send the MIDI clock from my computer at 60 bpm. If I take the midi output from my computer and put it in the input, MIDI-OX reads this:
If I put the output of the Arduino MIDI clock into my computer, it reads this:
the same thing...
Do any of you know what could cause my pedal to not sync at a lower BPM with the arduino? It works really well with my computer.
Also, I am a beginner so any tips to improve my code is appreciated! ![]()
Here is the code:
//Metronome with MIDI clock
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
using namespace midi;
void setup()
{
pinMode(8, OUTPUT); //LED
pinMode(6, INPUT); //On-Off button
MIDI.begin(31250);
}
int LED = 8;
int BOUTON = 6;
int NbPulse;
bool OnceRun;
bool OnceStop;
void ClockStart()
{
MIDI.sendRealTime(0xFA);
}
void ClockPulse()
{
MIDI.sendRealTime(0xF8);
}
void ClockStop()
{
MIDI.sendRealTime(0xFC);
}
void LedPulse ()
{
digitalWrite (LED, HIGH);
delay(5);
digitalWrite (LED, LOW);
}
void loop()
{
if (digitalRead (BOUTON))
{
if (OnceRun == 0)
{
ClockStart();
}
if (NbPulse == 0)
{
LedPulse();
}
ClockPulse();
delay(17); //This is where the value for the bpm will be (17ms = 150 bpm)
if (NbPulse < 23)
{
NbPulse = (NbPulse + 1);
}
else
{
NbPulse = 0;
}
OnceRun = 1;
OnceStop = 0;
}
else
{
if (OnceStop == 0)
{
ClockStop();
}
NbPulse = 0;
OnceRun = 0;
OnceStop = 1;
}
}




