#include "ESP8266WiFi.h" #include "WiFiUDP.h" #include "OSCMessage.h" int status = WL_IDLE_STATUS; const char* ssid = "YABR_OSC"; //任意 const char* pass = "*********"; //任意のパスワード int localPort = 8000; WiFiUDP Udp; void setup() { WiFi.softAP(ssid, pass); IPAddress myIP = WiFi.softAPIP(); Serial.print("AP IP address: "); Serial.println(myIP); Serial.println("Starting udp"); Udp.begin(localPort); Serial.print("Local port: "); Serial.println(Udp.localPort()); Serial.begin(9600); int tries = 0; while (WiFi.status() != WL_CONNECTED) { delay(500); tries++; if (tries > 30) { break; } } Udp.begin(localPort); } void loop() { OSCMsgReceive(); } void OSCMsgReceive() { OSCMessage msgIN; int size; if ((size = Udp.parsePacket()) > 0) { while (size--) msgIN.fill(Udp.read()); if (!msgIN.hasError()) { msgIN.route("/pad", xy); } } } void xy(OSCMessage &msg, int addrOffset) { int xValue; int yValue; xValue = msg.getFloat(0); yValue = msg.getFloat(1); if (xValue >= 96) { Serial.write(B00000001); } else if (xValue <= 32) { Serial.write(B00000010); } else if (yValue >= 96) { Serial.write(B00000100); } else if (yValue <= 32) { Serial.write(B00001000); } else { Serial.write(B00000000); } delay(5); } |