PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UDPSendBundle.ino 1.6KB

3 år sedan
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. Make an OSC bundle and send it over UDP
  3. OSCBundles allow OSCMessages to be grouped together
  4. to preserve the order and completeness of related messages.
  5. They also allow for timetags to be carried to represent the presentation time
  6. of the messages.
  7. */
  8. #include <Ethernet.h>
  9. #include <EthernetUdp.h>
  10. #include <SPI.h>
  11. #include <OSCBundle.h>
  12. EthernetUDP Udp;
  13. //the Arduino's IP
  14. IPAddress ip(128, 32, 122, 252);
  15. //destination IP
  16. IPAddress outIp(128, 32, 122, 125);
  17. const unsigned int outPort = 9999;
  18. byte mac[] = {
  19. 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // you can find this written on the board of some Arduino Ethernets or shields
  20. void setup() {
  21. Ethernet.begin(mac,ip);
  22. Udp.begin(8888);
  23. }
  24. void loop(){
  25. //declare the bundle
  26. OSCBundle bndl;
  27. //BOSCBundle's add' returns the OSCMessage so the message's 'add' can be composed together
  28. bndl.add("/analog/0").add((int32_t)analogRead(0));
  29. bndl.add("/analog/1").add((int32_t)analogRead(1));
  30. bndl.add("/digital/5").add((digitalRead(5)==HIGH)?"HIGH":"LOW");
  31. Udp.beginPacket(outIp, outPort);
  32. bndl.send(Udp); // send the bytes to the SLIP stream
  33. Udp.endPacket(); // mark the end of the OSC Packet
  34. bndl.empty(); // empty the bundle to free room for a new one
  35. bndl.add("/mouse/step").add((int32_t)analogRead(0)).add((int32_t)analogRead(1));
  36. bndl.add("/units").add("pixels");
  37. Udp.beginPacket(outIp, outPort);
  38. bndl.send(Udp); // send the bytes to the SLIP stream
  39. Udp.endPacket(); // mark the end of the OSC Packet
  40. bndl.empty(); // empty the bundle to free room for a new one
  41. delay(1000);
  42. }