PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SerialSendBundle.ino 1.6KB

3 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(Serial1);
  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. #if ARDUINO >= 100
  19. while(!Serial)
  20. ; // Leonardo bug
  21. #endif
  22. }
  23. void loop(){
  24. //declare the bundle
  25. OSCBundle bndl;
  26. //BOSCBundle's add' returns the OSCMessage so the message's 'add' can be composed together
  27. bndl.add("/analog/0").add((int32_t)analogRead(0));
  28. bndl.add("/analog/1").add((int32_t)analogRead(1));
  29. bndl.add("/digital/5").add((digitalRead(5)==HIGH)?"HIGH":"LOW");
  30. SLIPSerial.beginPacket();
  31. bndl.send(SLIPSerial); // send the bytes to the SLIP stream
  32. SLIPSerial.endPacket(); // mark the end of the OSC Packet
  33. bndl.empty(); // empty the bundle to free room for a new one
  34. bndl.add("/mouse/step").add((int32_t)analogRead(0)).add((int32_t)analogRead(1));
  35. bndl.add("/units").add("pixels");
  36. SLIPSerial.beginPacket();
  37. bndl.send(SLIPSerial); // send the bytes to the SLIP stream
  38. SLIPSerial.endPacket(); // mark the end of the OSC Packet
  39. bndl.empty(); // empty the bundle to free room for a new one
  40. delay(100);
  41. }