Coder Social home page Coder Social logo

Comments (1)

hideakitai avatar hideakitai commented on May 23, 2024
  osc.addCallback("/ard/aaa", &callback);
  osc.addCallback("/ard", &callback);

These are the "callback" function, so if the OSC message comes and the address of OSC is "/ard/aaa" or "/ard", callback() will be called.

  //create new osc message
  OSCMessage msg;
  //set destination ip address & port no
  msg.beginMessage(host, send_port);
  //set argument
  msg.setOSCAddress(m.getOSCAddress());
  msg.addArgInt32(m.getArgAsInt32(0));
  msg.addArgFloat(m.getArgAsFloat(1));
  msg.addArgString(m.getArgAsString(2));
  //send osc message
  osc.send(msg);
  Serial.println("Sent OSC message");

And these are the sequence to send OSC message. You can make sendOSC() function like

void sendOSC()
{
  //create new osc message
  OSCMessage msg;
  //set destination ip address & port no
  msg.beginMessage(host, send_port);
  //set argument
  msg.setOSCAddress("/return");
  msg.addArgInt32(1);
  msg.addArgFloat(2.2);
  msg.addArgString("return message");
  //send osc message
  osc.send(msg);
  Serial.println("Sent OSC message");
}

and also you can set this function to callback function like

void callback(OSCMessage& m)
{
	sendOSC();
}

then you can get

#include <ArduinoOSC.h>

void setup()
{
    // various settings...
    
  osc.addCallback("/ard/aaa", &sendTest1); // if "/ard/aaa XXX" has come, sendTest1() will be called
  osc.addCallback("/ard", &sendTest2); // if "/ard XXX" has come, sendTest2() will be called
}

void loop()
{
  osc.parse();
}

void sendTest1(OSCMessage& m)
{
  //create new osc message
  OSCMessage msg;
  //set destination ip address & port no
  msg.beginMessage(host, send_port);
  //set argument
  msg.setOSCAddress("/return");
  msg.addArgInt32(1);
  msg.addArgFloat(2.2);
  msg.addArgString("test");
  //send osc message
  osc.send(msg);
  Serial.println("Sent OSC message");
}

void sendTest2(OSCMessage& m)
{
  //create new osc message
  OSCMessage msg;
  //set destination ip address & port no
  msg.beginMessage(host, send_port);
  //set argument
  msg.setOSCAddress("/test");
  msg.addArgInt32(3);
  msg.addArgFloat(4.4);
  msg.addArgString("test2");
  //send osc message
  osc.send(msg);
  Serial.println("Sent OSC message");
}

or you can just send OSC message in one second

#include <ArduinoOSC.h>

void setup()
{
    // various settings...

    // no callback definition
//  osc.addCallback("/ard/aaa", &callback);
//  osc.addCallback("/ard", &callback);
}

void loop()
{
    // just send current time in one second
    
    delay(1000);
    
    //create new osc message
    OSCMessage msg;
    //set destination ip address & port no
    msg.beginMessage(host, send_port);
    //set argument
    msg.setOSCAddress("/test");
    msg.addArgInt32(millis()); // millis
    msg.addArgFloat((float)millis() / 1000.f); // second
    msg.addArgString("second");
    //send osc message
    osc.send(msg);
    Serial.println("Sent OSC message");
}

from arduinoosc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.