PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

54 Zeilen
1.3KB

  1. /*
  2. Serial USB ports are bidirectional.
  3. This example can be extended to build routers and forwarders of OSC packets
  4. */
  5. #include <OSCBundle.h>
  6. #ifdef BOARD_HAS_USB_SERIAL
  7. #include <SLIPEncodedUSBSerial.h>
  8. SLIPEncodedUSBSerial SLIPSerial( thisBoardsSerialUSB );
  9. #else
  10. #include <SLIPEncodedSerial.h>
  11. SLIPEncodedSerial SLIPSerial(Serial1);
  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. #if ARDUINO >= 100
  17. while(!Serial)
  18. ; // Leonardo bug
  19. #endif
  20. }
  21. void loop(){
  22. OSCBundle bndl;
  23. int size;
  24. //receive a bundle
  25. while(!SLIPSerial.endofPacket())
  26. if( (size =SLIPSerial.available()) > 0)
  27. {
  28. while(size--)
  29. bndl.fill(SLIPSerial.read());
  30. }
  31. if(!bndl.hasError())
  32. {
  33. static int32_t sequencenumber=0;
  34. // we can sneak an addition onto the end of the bundle
  35. bndl.add("/micros").add((int32_t)micros()); // (int32_t) is the type of OSC Integers
  36. bndl.add("/sequencenumber").add(sequencenumber++);
  37. bndl.add("/digital/5").add(digitalRead(5)==HIGH);
  38. bndl.add("/lsb").add((sequencenumber &1)==1);
  39. SLIPSerial.beginPacket(); // mark the beginning of the OSC Packet
  40. bndl.send(SLIPSerial);
  41. SLIPSerial.endPacket();
  42. }
  43. }