PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

71 行
1.5KB

  1. /*
  2. * Set the LED according to incoming OSC control
  3. */
  4. #include <OSCBundle.h>
  5. #include <OSCBoards.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 LEDcontrol(OSCMessage &msg)
  14. {
  15. if (msg.isInt(0))
  16. {
  17. pinMode(LED_BUILTIN, OUTPUT);
  18. digitalWrite(LED_BUILTIN, (msg.getInt(0) > 0)? HIGH: LOW);
  19. }
  20. else if(msg.isString(0))
  21. {
  22. int length=msg.getDataLength(0);
  23. if(length<5)
  24. {
  25. char str[length];
  26. msg.getString(0,str,length);
  27. if((strcmp("on", str)==0)|| (strcmp("On",str)==0))
  28. {
  29. pinMode(LED_BUILTIN, OUTPUT);
  30. digitalWrite(LED_BUILTIN, HIGH);
  31. }
  32. else if((strcmp("Of", str)==0)|| (strcmp("off",str)==0))
  33. {
  34. pinMode(LED_BUILTIN, OUTPUT);
  35. digitalWrite(LED_BUILTIN, LOW);
  36. }
  37. }
  38. }
  39. }
  40. void setup() {
  41. SLIPSerial.begin(9600); // set this as high as you can reliably run on your platform
  42. #if ARDUINO >= 100
  43. while(!Serial)
  44. ; // Leonardo bug
  45. #endif
  46. }
  47. //reads and dispatches the incoming message
  48. void loop(){
  49. OSCBundle bundleIN;
  50. int size;
  51. while(!SLIPSerial.endofPacket())
  52. if( (size =SLIPSerial.available()) > 0)
  53. {
  54. while(size--)
  55. bundleIN.fill(SLIPSerial.read());
  56. }
  57. if(!bundleIN.hasError())
  58. bundleIN.dispatch("/led", LEDcontrol);
  59. }