forest-all-around/osc/lib/OSC/examples/SerialSendBundle/SerialSendBundle.ino
Dooho Yi fa1acde77b rename osc8266/ -> osc/
+ (planned) add support for esp32
2022-05-04 15:50:38 +09:00

50 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Make an OSC bundle and send it over SLIP serial
OSCBundles allow OSCMessages to be grouped together to preserve the order and completeness of related messages.
They also allow for timetags to be carried to represent the presentation time of the messages.
*/
#include <OSCBundle.h>
#include <OSCBoards.h>
#ifdef BOARD_HAS_USB_SERIAL
#include <SLIPEncodedUSBSerial.h>
SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
#else
#include <SLIPEncodedSerial.h>
SLIPEncodedSerial SLIPSerial(Serial); // Change to Serial1 or Serial2 etc. for boards with multiple serial ports that dont have Serial
#endif
void setup() {
//begin SLIPSerial just like Serial
SLIPSerial.begin(9600); // set this as high as you can reliably run on your platform
}
void loop(){
//declare the bundle
OSCBundle bndl;
//BOSCBundle's add' returns the OSCMessage so the message's 'add' can be composed together
bndl.add("/analog/0").add((int32_t)analogRead(0));
bndl.add("/analog/1").add((int32_t)analogRead(1));
bndl.add("/digital/5").add((digitalRead(5)==HIGH)?"HIGH":"LOW");
SLIPSerial.beginPacket();
bndl.send(SLIPSerial); // send the bytes to the SLIP stream
SLIPSerial.endPacket(); // mark the end of the OSC Packet
bndl.empty(); // empty the bundle to free room for a new one
bndl.add("/mouse/step").add((int32_t)analogRead(0)).add((int32_t)analogRead(1));
bndl.add("/units").add("pixels");
SLIPSerial.beginPacket();
bndl.send(SLIPSerial); // send the bytes to the SLIP stream
SLIPSerial.endPacket(); // mark the end of the OSC Packet
bndl.empty(); // empty the bundle to free room for a new one
delay(100);
}