Merge pull request #22 from Jackson-Devices/patch-1

Update STM32UartMasterMidiClock.ino for tested example
pull/24/head
midilab 2 years ago committed by GitHub
commit 9b7abae36b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      examples/STM32UartMasterMidiClock/STM32UartMasterMidiClock.ino

@ -1,12 +1,19 @@
/* Uart MIDI Sync Box /* Uart MIDI out
* *
* This example demonstrates how to send MIDI data via Uart * This example demonstrates how to send MIDI data via Uart
* interface on STM32 family. * interface on STM32 family.
* *
* This example code is in the public domain. * This example code is in the public domain.
* *
* ... * Requires STM32Duino board manager to be installed.
* *
* Define HardwareSerial using any available UART/USART.
* Nucleo boards have UART/USART pins that are used by the ST-LINK interface (unless using solder bridging).
*
* Tested on Nucleo-F401RE and Nucleo-F072RB (PA9=D8 PA10=D2 on the Arduino pins)
*
* Code by midilab contact@midilab.co
* Example modified by Jackson Devices contact@jacksondevices.com
*/ */
#include <uClock.h> #include <uClock.h>
@ -15,8 +22,7 @@
#define MIDI_START 0xFA #define MIDI_START 0xFA
#define MIDI_STOP 0xFC #define MIDI_STOP 0xFC
// the blue led HardwareSerial Serial1(PA10, PA9);
#define LED_BUILTIN 2
uint8_t bpm_blink_timer = 1; uint8_t bpm_blink_timer = 1;
void handle_bpm_led(uint32_t tick) void handle_bpm_led(uint32_t tick)
@ -35,24 +41,26 @@ void handle_bpm_led(uint32_t tick)
// Internal clock handlers // Internal clock handlers
void ClockOut96PPQN(uint32_t tick) { void ClockOut96PPQN(uint32_t tick) {
// Send MIDI_CLOCK to external gears // Send MIDI_CLOCK to external gear
//Serial.write(MIDI_CLOCK); Serial1.write(MIDI_CLOCK);
handle_bpm_led(tick); handle_bpm_led(tick);
} }
void onClockStart() { void onClockStart() {
//Serial.write(MIDI_START); // Send MIDI_START to external gear
Serial1.write(MIDI_START);
} }
void onClockStop() { void onClockStop() {
//Serial.write(MIDI_STOP); // Send MIDI_STOP to external gear
Serial1.write(MIDI_STOP);
} }
void setup() { void setup() {
// Initialize serial communication at 31250 bits per second, the default MIDI serial speed communication: // Initialize Serial1 communication at 31250 bits per second, the default MIDI Serial1 speed communication:
//Serial.begin(31250); Serial1.begin(31250);
// A led to count bpms // An led to display BPM
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
// Setup our clock system // Setup our clock system
@ -64,7 +72,7 @@ void setup() {
uClock.setOnClockStartOutput(onClockStart); uClock.setOnClockStartOutput(onClockStart);
uClock.setOnClockStopOutput(onClockStop); uClock.setOnClockStopOutput(onClockStop);
// Set the clock BPM to 126 BPM // Set the clock BPM to 126 BPM
uClock.setTempo(126); uClock.setTempo(120);
// Starts the clock, tick-tac-tick-tac... // Starts the clock, tick-tac-tick-tac...
uClock.start(); uClock.start();
} }

Loading…
Cancel
Save