SerialSendMessage.ino 901 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <OSCMessage.h>
  2. #include <OSCBoards.h>
  3. /*
  4. Make an OSC message and send it over serial
  5. */
  6. #ifdef BOARD_HAS_USB_SERIAL
  7. #include <SLIPEncodedUSBSerial.h>
  8. SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
  9. #else
  10. #include <SLIPEncodedSerial.h>
  11. SLIPEncodedSerial SLIPSerial(Serial); // Change to Serial1 or Serial2 etc. for boards with multiple serial ports that don’t have Serial
  12. #endif
  13. void setup() {
  14. //begin SLIPSerial just like Serial
  15. SLIPSerial.begin(9600); // set this as high as you can reliably run on your platform
  16. }
  17. void loop(){
  18. //the message wants an OSC address as first argument
  19. OSCMessage msg("/analog/0");
  20. msg.add((int32_t)analogRead(0));
  21. SLIPSerial.beginPacket();
  22. msg.send(SLIPSerial); // send the bytes to the SLIP stream
  23. SLIPSerial.endPacket(); // mark the end of the OSC Packet
  24. msg.empty(); // free space occupied by message
  25. delay(20);
  26. }