Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Midi5Pin.cpp
- Committer:
- mpetrut
- Date:
- 2015-10-22
- Revision:
- 6:08234a5a8598
- Parent:
- 1:399a3ad230c8
File content as of revision 6:08234a5a8598:
/* Simple mbed 5-pin DIN to USB MIDI Converter library
Marius Petrut, 2015
*/
#include "Midi5Pin.h"
#include "mbed.h"
#define NOTE_ON 144
#define CONT_CTRL 176
Midi5Pin::Midi5Pin(PinName txPin, PinName rxPin) :
_pc(USBTX, USBRX), _uart5pin(txPin, rxPin) {
_pc.baud(115200);
// 31250 is the official specification
_uart5pin.baud(31250);
}
void Midi5Pin::write(char command, char param1, char param2) {
_uart5pin.putc(command);
_uart5pin.putc(param1);
_uart5pin.putc(param2);
}
void Midi5Pin::noteOn(char note, char velocity) {
_uart5pin.putc(NOTE_ON);
_uart5pin.putc(note);
_uart5pin.putc(velocity);
}
void Midi5Pin::noteOff(char note) {
_uart5pin.putc(NOTE_ON);
_uart5pin.putc(note);
_uart5pin.putc(0);
}
void Midi5Pin::contCtrl(char ccNumber, char value) {
_uart5pin.putc(CONT_CTRL);
_uart5pin.putc(ccNumber);
_uart5pin.putc(value);
}
void Midi5Pin::read() {
if (_uart5pin.readable()) {
_pc.putc(_uart5pin.getc());
}
}
5-Pin DIN MIDI Connector