OSC ESP32 MAX

sketch arduino pour ESP32 envoi et reception de trame OSC :

include WiFi.h

include WiFiUdp.h

include OSCMessage.h

int LED_BUILTIN = 2;
int update_rate = 16;

char ssid[] = « xxxxx »; // your network SSID (name)
char pass[] = « xxxxxx »; // your network password

WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
const IPAddress outIp(192,168,0,10); // remote IP of your computer
const unsigned int outPort = 9999; // remote port to receive OSC
const unsigned int localPort = 8888; // local port to listen for OSC packets (actually not used for sending)

void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print(« Connecting to « );
Serial.println(ssid);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(« . »);
}
Serial.println(«  »);

Serial.println(« WiFi connected »);
Serial.println(« IP address: « );
Serial.println(WiFi.localIP());

Serial.println(« Starting UDP »);
Udp.begin(localPort);
Serial.print(« Local port: « );
// Serial.println(Udp.localPort());

}

void ledtoggle(OSCMessage &msg) {
switch (msg.getInt(0)) {
case 0:
digitalWrite(LED_BUILTIN, LOW);
break;
case 1:
digitalWrite(LED_BUILTIN, HIGH);
break;
}
}

void receiveMessage() {
OSCMessage inmsg;
int size = Udp.parsePacket();

if (size > 0) {
while (size–) {
inmsg.fill(Udp.read());
}
if (!inmsg.hasError()) {
inmsg.dispatch(« /led », ledtoggle);
}
//else { auto error = inmsg.getError(); }
}
}

void loop() {
receiveMessage();

OSCMessage msg2(« /touch »);
msg2.add(touchRead(4));
Udp.beginPacket(outIp, outPort);
msg2.send(Udp);
Udp.endPacket();
msg2.empty();
delay(update_rate);

}

Max Patch :

CATEGORIES:

max

Tags:

Comments are closed