|
-
- #include <Ethernet.h>
- #include <EthernetUdp.h>
- #include <SPI.h>
-
- #include <OSCBundle.h>
- #include <OSCBoards.h>
-
-
-
-
-
-
- EthernetUDP Udp;
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
-
-
- IPAddress ip(128, 32, 122, 252);
-
-
- const unsigned int inPort = 8888;
-
-
- char * numToOSCAddress( int pin){
- static char s[10];
- int i = 9;
-
- s[i--]= '\0';
- do
- {
- s[i] = "0123456789"[pin % 10];
- --i;
- pin /= 10;
- }
- while(pin && i);
- s[i] = '/';
- return &s[i];
- }
-
-
-
- void routeTone(OSCMessage &msg, int addrOffset ){
-
- for(byte pin = 0; pin < NUM_DIGITAL_PINS; pin++){
-
- int pinMatched = msg.match(numToOSCAddress(pin), addrOffset);
- if(pinMatched){
- unsigned int frequency = 0;
-
- if (msg.isInt(0)){
- frequency = msg.getInt(0);
- }
- else if(msg.isFloat(0)){
- frequency = msg.getFloat(0);
- }
- else
- noTone(pin);
- if(frequency>0)
- {
- if(msg.isInt(1))
- tone(pin, frequency, msg.getInt(1));
- else
- tone(pin, frequency);
- }
- }
- }
- }
-
- void setup() {
-
- Ethernet.begin(mac,ip);
- Udp.begin(inPort);
-
- }
-
- void loop(){
- OSCBundle bundleIN;
- int size;
-
- if( (size = Udp.parsePacket())>0)
- {
- while(size--)
- bundleIN.fill(Udp.read());
-
- if(!bundleIN.hasError())
- bundleIN.route("/tone", routeTone);
- }
- }
-
|