|
|
|
#include "Arduino.h"
|
|
|
|
#include <uClock.h>
|
|
|
|
|
|
|
|
// MIDI clock, start and stop byte definitions - based on MIDI 1.0 Standards.
|
|
|
|
#define MIDI_CLOCK 0xF8
|
|
|
|
#define MIDI_START 0xFA
|
|
|
|
#define MIDI_STOP 0xFC
|
|
|
|
|
|
|
|
// The callback function wich will be called by Clock each Pulse of 24PPQN clock resolution.
|
|
|
|
void onSync24Callback(uint32_t tick)
|
|
|
|
{
|
|
|
|
// Send MIDI_CLOCK to external gears
|
|
|
|
Serial.write(MIDI_CLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The callback function wich will be called when clock starts by using Clock.start() method.
|
|
|
|
void onClockStart()
|
|
|
|
{
|
|
|
|
Serial.write(MIDI_START);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The callback function wich will be called when clock stops by using Clock.stop() method.
|
|
|
|
void onClockStop()
|
|
|
|
{
|
|
|
|
Serial.write(MIDI_STOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
|
|
|
|
// Initialize serial communication at 31250 bits per second, the default MIDI serial speed communication:
|
|
|
|
Serial.begin(31250);
|
|
|
|
|
|
|
|
// Inits the clock
|
|
|
|
uClock.init();
|
|
|
|
// Set the callback function for the clock output to send MIDI Sync message.
|
|
|
|
uClock.setOnSync24(onSync24Callback);
|
|
|
|
// Set the callback function for MIDI Start and Stop messages.
|
|
|
|
uClock.setOnClockStart(onClockStart);
|
|
|
|
uClock.setOnClockStop(onClockStop);
|
|
|
|
// Set the clock BPM to 126 BPM
|
|
|
|
uClock.setTempo(126);
|
|
|
|
|
|
|
|
// Starts the clock, tick-tac-tick-tac...
|
|
|
|
uClock.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do it whatever to interface with Clock.stop(), Clock.start(), Clock.setTempo() and integrate your environment...
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|