Go Down

Topic: updated OSC library for 0021 (Read 2843 times) previous topic - next topic

nickv

I've done a little bit of work and updated Recotana's OSC library to work with 0021. I haven't tested it extensively so please let me know how it work out for you.

Download Library:
http://www.makesomecode.com/wp-content/uploads/2010/11/OSCClass.zip

razic

can you show the code you used to get this working?

DodgyBob

I tried to get it working but it doesn't seem to do anything with the standard LED example sketch :-/
Code: [Select]
// OSCClass iOSC(iPhone App) test sketch
// OSCClass version 1.0.1 (Arduino ver0014)
// Copyright (c) recotana.  All right reserved.

/*

iOSC setting
           OSCMessage    type  value on  off
button1    /ard/ledyel    int          1   0   :info-AlternateMode "ON" =toggle sw
button2    /ard/ledgrn    int          1   0
button3    /ard/ledred    int          1   0
slider1    /ard/ledpwm    int  min:0 max:255

host setting IP address 192.168.1.99 , port 10000

*/

#include "Ethernet.h"
#include "OSCClass.h"
#include "SPI.h"


#define  LED_RED 2
#define  LED_GRN 3
#define  LED_YEL 4
#define  LED_PWM 6

 OSCMessage recMes;
 
 OSCClass osc(&recMes);

 byte serverMac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x2A, 0x69 };
 byte serverIp[]  = { 192, 168, 1, 99 };
 int  serverPort  = 10000;
 
 byte gateway[]   = { 192, 168, 1, 1 };
 byte subnet[]    = { 255, 255, 255, 0 };

 
 char *topAddress="/ard";
 char *subAddress[4]={ "/ledred" , "/ledgrn" , "/ledyel" , "/ledpwm"};
 

 
void setup() {
 
      //for message logging
     
   Serial.begin(19200);
 
 
     
 //  Ethernet.begin(serverMac ,serverIp);
 Ethernet.begin(serverMac ,serverIp ,gateway ,subnet);
   
    //setting osc recieve server
    osc.begin(serverPort);
   
    pinMode(LED_RED, OUTPUT);
    pinMode(LED_GRN, OUTPUT);
    pinMode(LED_YEL, OUTPUT);
    pinMode(LED_PWM, OUTPUT);

    digitalWrite(LED_RED, HIGH);  //LED OFF
    digitalWrite(LED_GRN, HIGH);  //LED OFF
    digitalWrite(LED_YEL, HIGH);  //LED OFF
    digitalWrite(LED_PWM, HIGH);  //LED OFF
 

   //osc message buffer clear
    osc.flush();
   
}

void loop() {

   //osc arrive check
   if ( osc.available() ) {
     
logMessage(&recMes);


         //toplevel address matching
         if( !strcmp( recMes.getAddress(0) , topAddress ) ){
                           
             //second level address matching          
               if( !strcmp( recMes.getAddress(1) , subAddress[0] ) ){
                         
                     red();
               
               }
               
               else if( !strcmp( recMes.getAddress(1) , subAddress[1] ) ){
                         
                     green();
               
               }
               else if( !strcmp( recMes.getAddress(1) , subAddress[2] ) ){
                         
                     yellow();
               
               }
               
               else if( !strcmp( recMes.getAddress(1) , subAddress[3] ) ){
                         
                     pwm();
               
               }
               
 
         }

   }
   

}

void red(){

  if(recMes.getArgInt(0) == 1){  
         digitalWrite(LED_RED, LOW);  //LED_ON
  }
  else{
         digitalWrite(LED_RED, HIGH);  //LED OFF
  }
 
}

void green(){

  if(recMes.getArgInt(0) == 1){  
         digitalWrite(LED_GRN, LOW);  //LED_ON
  }
  else{
         digitalWrite(LED_GRN, HIGH);  //LED OFF
  }
 
}

void yellow(){

  if(recMes.getArgInt(0) == 1){  
         digitalWrite(LED_YEL, LOW);  //LED_ON
  }
  else{
         digitalWrite(LED_YEL, HIGH);  //LED OFF
  }
 
}

void pwm(){
 byte value=(byte)recMes.getArgInt(0);
 analogWrite(LED_PWM, 255-value);
 
}



// *********  utility  ***********************************


void logMessage(OSCMessage *mes){
 
   uint8_t *ip=mes->getIp();
 
    //disp ip & port
   Serial.print("from IP:");
   Serial.print(ip[0],DEC);
   Serial.print(".");
   Serial.print(ip[1],DEC);
   Serial.print(".");
   Serial.print(ip[2],DEC);
   Serial.print(".");
   Serial.print(ip[3],DEC);
   Serial.print(" port:");
   Serial.print(mes->getPort(),DEC);
   Serial.print("   ");
   
   //disp adr
   for(int i = 0 ; i < mes->getAddressNum() ; i++){
     
     Serial.print(mes->getAddress(i));
     
   }
   
   
   //disp type tags
   Serial.print("  ,");
   for(int i = 0 ; i < mes->getArgNum() ; i++){
     
     Serial.print(mes->getTypeTag(i));
     
   }
   Serial.print(" ");
 
 
  //disp args
   for(int i = 0 ; i < mes->getArgNum() ; i++){
     
     switch( mes->getTypeTag(i) ){
       
       case 'i': {
                     
                     Serial.print( mes->getArgInt(i) );
                 }
         break;
       
       case 'f':  {
                     
                     Serial.print( mes->getArgFloat(i) );
                 }
         break;
       
     }
     
      Serial.print(" ");
     
   }
   
   Serial.println("");
   
}


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy