SerialSendBundle.ino 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Make an OSC bundle and send it over SLIP serial
  3. OSCBundles allow OSCMessages to be grouped together to preserve the order and completeness of related messages.
  4. They also allow for timetags to be carried to represent the presentation time of the messages.
  5. */
  6. #include <OSCBundle.h>
  7. #include <OSCBoards.h>
  8. #ifdef BOARD_HAS_USB_SERIAL
  9. #include <SLIPEncodedUSBSerial.h>
  10. SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
  11. #else
  12. #include <SLIPEncodedSerial.h>
  13. SLIPEncodedSerial SLIPSerial(Serial); // Change to Serial1 or Serial2 etc. for boards with multiple serial ports that don’t have Serial
  14. #endif
  15. void setup() {
  16. //begin SLIPSerial just like Serial
  17. SLIPSerial.begin(9600); // set this as high as you can reliably run on your platform
  18. }
  19. void loop(){
  20. //declare the bundle
  21. OSCBundle bndl;
  22. //BOSCBundle's add' returns the OSCMessage so the message's 'add' can be composed together
  23. bndl.add("/analog/0").add((int32_t)analogRead(0));
  24. bndl.add("/analog/1").add((int32_t)analogRead(1));
  25. bndl.add("/digital/5").add((digitalRead(5)==HIGH)?"HIGH":"LOW");
  26. SLIPSerial.beginPacket();
  27. bndl.send(SLIPSerial); // send the bytes to the SLIP stream
  28. SLIPSerial.endPacket(); // mark the end of the OSC Packet
  29. bndl.empty(); // empty the bundle to free room for a new one
  30. bndl.add("/mouse/step").add((int32_t)analogRead(0)).add((int32_t)analogRead(1));
  31. bndl.add("/units").add("pixels");
  32. SLIPSerial.beginPacket();
  33. bndl.send(SLIPSerial); // send the bytes to the SLIP stream
  34. SLIPSerial.endPacket(); // mark the end of the OSC Packet
  35. bndl.empty(); // empty the bundle to free room for a new one
  36. delay(100);
  37. }