brix5 / firmware / sliposc / SerialSendMessage / SerialSendMessage.ino @ edc6c2e7
History | View | Annotate | Download (978 Bytes)
| 1 | f175b4b0 | Jan | // vim:ts=2:sw=2:expandtab |
|---|---|---|---|
| 2 | // OSC Lib Example |
||
| 3 | // messages work fine over slip udp, |
||
| 4 | // osc bundles likely require tcp stream |
||
| 5 | #include "OSC/OSCMessage.h" |
||
| 6 | |||
| 7 | /* Make an OSC message and send it over serial */ |
||
| 8 | |||
| 9 | #ifdef BOARD_HAS_USB_SERIAL |
||
| 10 | #include <SLIPEncodedUSBSerial.h> |
||
| 11 | SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB ); |
||
| 12 | #else |
||
| 13 | #include <SLIPEncodedSerial.h> |
||
| 14 | SLIPEncodedSerial SLIPSerial(Serial1); |
||
| 15 | #endif |
||
| 16 | |||
| 17 | |||
| 18 | void setup() {
|
||
| 19 | //begin SLIPSerial just like Serial |
||
| 20 | SLIPSerial.begin(9600); // set this as high as you can reliably run on your platform |
||
| 21 | #if ARDUINO >= 100 |
||
| 22 | while(!Serial) |
||
| 23 | ; //Leonardo "feature" |
||
| 24 | #endif |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | void loop(){
|
||
| 29 | //the message wants an OSC address as first argument |
||
| 30 | OSCMessage msg("/analog/0");
|
||
| 31 | msg.add((int32_t)analogRead(0)); |
||
| 32 | |||
| 33 | SLIPSerial.beginPacket(); |
||
| 34 | msg.send(SLIPSerial); // send the bytes to the SLIP stream |
||
| 35 | SLIPSerial.endPacket(); // mark the end of the OSC Packet |
||
| 36 | msg.empty(); // free space occupied by message |
||
| 37 | |||
| 38 | delay(20); |
||
| 39 | } |