SerialSendMessage.ino 850 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <OSCMessage.h>
  2. /*
  3. Make an OSC message and send it over serial
  4. */
  5. #ifdef BOARD_HAS_USB_SERIAL
  6. #include <SLIPEncodedUSBSerial.h>
  7. SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
  8. #else
  9. #include <SLIPEncodedSerial.h>
  10. SLIPEncodedSerial SLIPSerial(Serial1);
  11. #endif
  12. void setup() {
  13. //begin SLIPSerial just like Serial
  14. SLIPSerial.begin(9600); // set this as high as you can reliably run on your platform
  15. #if ARDUINO >= 100
  16. while(!Serial)
  17. ; //Leonardo "feature"
  18. #endif
  19. }
  20. void loop(){
  21. //the message wants an OSC address as first argument
  22. OSCMessage msg("/analog/0");
  23. msg.add((int32_t)analogRead(0));
  24. SLIPSerial.beginPacket();
  25. msg.send(SLIPSerial); // send the bytes to the SLIP stream
  26. SLIPSerial.endPacket(); // mark the end of the OSC Packet
  27. msg.empty(); // free space occupied by message
  28. delay(20);
  29. }