WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP constunsignedint localPort = 8000; // local port to listen for UDP packets at the NodeMCU (another device must send OSC messages to this port) constunsignedint destPort = 9000; // remote port of the target device where the NodeMCU sends OSC to
voidOSC(){ OSCMessage msgIN; intsize; if ((size = Udp.parsePacket()) > 0) { while (size--) msgIN.fill(Udp.read()); if (!msgIN.hasError()) { msgIN.route("/led", led); //if message is come from "/led",it will run function led msgIN.route("/analogLed", led2); //if message is come from "/led",it will run function led } } }
voidled(OSCMessage &msg, int addrOffset){ ledState = msg.getInt(0); //save recivied data to ledState }
voidled2(OSCMessage &msg, int addrOffset){ inputAnalog = msg.getInt(0); //save recivied data to ledState }
voidloop(){ OSC(); digitalWrite(digitalLed,ledState);//if led State is 0,led will be light(nodemcu's LED_BUILTIN is reversed logic) analogWrite(analogLed,inputAnalog); }
// OSC OscP5 oscP5; ControlP5 cp5; NetAddress NodeMCULocation; String HOST = "nodemcu's IP"; //nodemcu's IP int HOST_PORT = 8000; //port for Ground_Control Computer int LOCAL_PORT = 9000; //port for my incoming port
int slider = 0; int preSlider; boolean toggle = false; boolean preToggle;