brix5 / firmware / sliposc / SerialSendBundle / SerialSendBundle.ino @ master
History | View | Annotate | Download (1.763 KB)
1 | f175b4b0 | Jan | // vim:ts=2:sw=2:expandtab |
---|---|---|---|
2 | // OSC Lib Example for w/ and w/o timetag |
||
3 | |||
4 | /* |
||
5 | Make an OSC bundle and send it over SLIP serial |
||
6 | |||
7 | OSCBundles allow OSCMessages to be grouped together to preserve the order and completeness of related messages. |
||
8 | They also allow for timetags to be carried to represent the presentation time of the messages. |
||
9 | */ |
||
10 | #include "OSC/OSCBundle.h" |
||
11 | #include "OSC/OSCBoards.h" |
||
12 | #include "OSC/OSCTiming.h" |
||
13 | |||
14 | #ifdef BOARD_HAS_USB_SERIAL |
||
15 | #include <SLIPEncodedUSBSerial.h> |
||
16 | SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB ); |
||
17 | #else |
||
18 | #include <SLIPEncodedSerial.h> |
||
19 | SLIPEncodedSerial SLIPSerial(Serial1); |
||
20 | #endif |
||
21 | |||
22 | |||
23 | void setup() { |
||
24 | //begin SLIPSerial just like Serial |
||
25 | SLIPSerial.begin(9600); // set this as high as you can reliably run on your platform |
||
26 | #if ARDUINO >= 100 |
||
27 | while(!Serial) |
||
28 | ; // Leonardo bug |
||
29 | #endif |
||
30 | |||
31 | } |
||
32 | |||
33 | void loop(){ |
||
34 | //declare the bundle |
||
35 | OSCBundle bndl; |
||
36 | osctime_t timetag; |
||
37 | |||
38 | //OSCBundle's add' returns the OSCMessage so the message's 'add' can be composed together |
||
39 | |||
40 | // with timetag |
||
41 | bndl.add("/analog/0").add((int32_t)adcRead(0, &timetag)); |
||
42 | bndl.add("/analog/0/time").add(timetag); |
||
43 | |||
44 | bndl.add("/analog/1").add((int32_t)adcRead(1, &timetag)); |
||
45 | bndl.add("/analog/1/time").add(timetag); |
||
46 | |||
47 | bndl.add("/digital/5").add((digitalRead(5)==HIGH)?"HIGH":"LOW"); |
||
48 | |||
49 | |||
50 | bndl.add("/analog/2").add((int32_t)analogRead(2)); |
||
51 | bndl.add("/analog/3").add((int32_t)analogRead(3)); |
||
52 | bndl.add("/digital/4").add((digitalRead(4)==HIGH)?"HIGH":"LOW"); |
||
53 | |||
54 | SLIPSerial.beginPacket(); |
||
55 | bndl.setTimetag(oscTime()); |
||
56 | bndl.send(SLIPSerial); // send the bytes to the SLIP stream |
||
57 | SLIPSerial.endPacket(); // mark the end of the OSC Packet |
||
58 | bndl.empty(); // empty the bundle to free room for a new one |
||
59 | |||
60 | delay(100); |
||
61 | } |