Skip to content

Instantly share code, notes, and snippets.

@BorisKourt
Created April 20, 2020 13:37
Show Gist options
  • Save BorisKourt/26ac130cab775773c7dc31da42ebd521 to your computer and use it in GitHub Desktop.
Save BorisKourt/26ac130cab775773c7dc31da42ebd521 to your computer and use it in GitHub Desktop.
[Musicbox] OSC via Serial
// This code runs on the Teensy
// Uses https://github.com/CNMAT/OSC
// It sends a bundle, 0 - 1 for each musicbox
// In order to make sure that there is clear start
// and stop to the packets SLIP is used:
// https://en.wikipedia.org/wiki/Serial_Line_Internet_Protocol
// As this sketch is incredibly minimal, the
// OSC library above is effectively the documentation.
// A MAX example is available at:
// https://github.com/CNMAT/OSC/tree/master/Applications/MaxMSP/examples
#include <OSCBundle.h>
#include <OSCBoards.h>
#include <OSCTiming.h>
#ifdef BOARD_HAS_USB_SERIAL
#include <SLIPEncodedUSBSerial.h>
SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
#else
#include <SLIPEncodedSerial.h>
SLIPEncodedSerial SLIPSerial(Serial1);
#endif
const uint8_t mbox_0 = 14;
const uint8_t mbox_1 = 15;
const uint8_t mbox_2 = 16;
const uint8_t mbox_3 = 17;
void setup() {
SLIPSerial.begin(500000);
pinMode(mbox_0,INPUT_PULLUP);
pinMode(mbox_1,INPUT_PULLUP);
pinMode(mbox_2,INPUT_PULLUP);
pinMode(mbox_3,INPUT_PULLUP);
}
void loop() {
OSCBundle bndl;
bndl.add("/mbox/0").add((int32_t)digitalRead(mbox_0));
bndl.add("/mbox/1").add((int32_t)digitalRead(mbox_1));
bndl.add("/mbox/2").add((int32_t)digitalRead(mbox_2));
bndl.add("/mbox/3").add((int32_t)digitalRead(mbox_3));
SLIPSerial.beginPacket();
bndl.setTimetag(oscTime());
bndl.send(SLIPSerial);
SLIPSerial.endPacket();
bndl.empty();
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment