#include #include const int C_WHITEHEAD = 1; const int C_WHITEFEED = 2; const int C_BLACKFEED = 3; const int C_BLACKHEAD = 4; Adafruit_MotorShield AFMS = Adafruit_MotorShield(); Adafruit_DCMotor* blackHead = AFMS.getMotor(C_BLACKHEAD); Adafruit_DCMotor* blackFeed = AFMS.getMotor(C_BLACKFEED); Adafruit_DCMotor* whiteFeed = AFMS.getMotor(C_WHITEFEED); Adafruit_DCMotor* whiteHead = AFMS.getMotor(C_WHITEHEAD); // customise as needed const char* ssid = "XPUB"; const char* password = "5fff132d"; const char* host = "192.168.1.174"; const IPAddress ip(192, 168, 1, 171); const IPAddress gateway(192, 168, 1, 1); const IPAddress subnet(255, 255, 255, 0); const int recv_port = 10000; const int send_port = 6060; int blackHeadSpeed = 150; int blackFeedSpeed = 150; int whiteFeedSpeed = 150; int whiteHeadSpeed = 150; int STATE_SOLO = 0; bool featureSolo = false; bool featureB2 = false; bool featureB4 = false; bool featureB5 = false; float b2Val = 1; String b4Val = "chop"; float b5Val = 1; String b4choices[2] = { "feed", "head" }; void setup() { Serial.begin(115200); // WiFi Stuff // WiFi.setMinSecurity(WIFI_AUTH_WPA_PSK); // didnt work on esp? // WiFi.mode(WIFI_MODE_STA); // didnt work on esp? WiFi.begin(ssid, password); WiFi.config(ip, gateway, subnet); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); WiFi.localIP(); }; if (!AFMS.begin()) { # here for pwm Serial.println("Could not find Motor Shield. Check wiring."); while (1) ; }; Serial.println(""); Serial.println("WiFi connected."); Serial.print("IP address: "); Serial.println(WiFi.localIP()); Serial.print("ESP CPU Frequency in MHz: "); Serial.println(ESP.getCpuFreqMHz()); whiteHead->setSpeed(whiteHeadSpeed); whiteHead->run(RELEASE); blackHead->setSpeed(blackHeadSpeed); blackHead->run(RELEASE); whiteFeed->setSpeed(whiteFeedSpeed); whiteFeed->run(RELEASE); blackFeed->setSpeed(blackFeedSpeed); blackFeed->run(RELEASE); OscWiFi.subscribe(recv_port, "/stopall", [](const OscMessage& m) { blackFeed->run(RELEASE); blackHead->run(RELEASE); whiteFeed->run(RELEASE); whiteHead->run(RELEASE); }); OscWiFi.subscribe(recv_port, "/black/feed/*", [](const OscMessage& m) { float tidalSpeed = m.arg(0); String address = m.address(); // Serial.println(address); if (STATE_SOLO == C_BLACKFEED || STATE_SOLO == 0) { Serial.println(address); if (address == "/black/feed/f") { blackFeed->run(FORWARD); } else if (address == "/black/feed/b") { blackFeed->run(BACKWARD); } else if (address == "/black/feed/r") { blackFeed->run(RELEASE); } else if (address == "/black/feed/speed") { blackFeedSpeed = tidalSpeed; blackFeed->setSpeed(blackFeedSpeed); } else { Serial.println("dont know what to do with this OSC"); }; } else { Serial.println("dont mind me, feeds' not part of this solo"); }; }); OscWiFi.subscribe(recv_port, "/white/feed/*", [](const OscMessage& m) { float tidalSpeed = m.arg(0); String address = m.address(); // Serial.println(address); if (STATE_SOLO == C_WHITEFEED || STATE_SOLO == 0) { Serial.println(address); if (address == "/white/feed/f") { whiteFeed->run(FORWARD); } else if (address == "/white/feed/b") { whiteFeed->run(BACKWARD); } else if (address == "/white/feed/r") { whiteFeed->run(RELEASE); } else if (address == "/black/feed/speed") { whiteFeedSpeed = tidalSpeed; whiteFeed->setSpeed(whiteFeedSpeed); } else { Serial.println("dont know what to do with this OSC"); }; } else { Serial.println("dont mind me, feeds' not part of this solo"); }; }); OscWiFi.subscribe(recv_port, "/black/head/*", [](const OscMessage& m) { float tidalSpeed = m.arg(0); String address = m.address(); // Serial.println(address); if (STATE_SOLO == C_BLACKHEAD || STATE_SOLO == 0) { Serial.println(address); if (address == "/black/head/f") { blackHead->run(FORWARD); } else if (address == "/black/head/b") { blackHead->run(BACKWARD); } else if (address == "/black/head/r") { blackHead->run(RELEASE); } else if (address == "/black/head/speed") { blackHeadSpeed = tidalSpeed; blackHead->setSpeed(blackHeadSpeed); } else { Serial.println("dont know what to do with this OSC"); }; } else { Serial.println("dont mind me, heads' not part of this solo"); }; }); OscWiFi.subscribe(recv_port, "/white/head/*", [](const OscMessage& m) { float tidalSpeed = m.arg(0); String address = m.address(); // Serial.println(address); if (STATE_SOLO == C_WHITEHEAD || STATE_SOLO == 0) { Serial.println(address); if (address == "/white/head/f") { whiteHead->run(FORWARD); } else if (address == "/white/head/b") { whiteHead->run(BACKWARD); } else if (address == "/white/head/r") { whiteHead->run(RELEASE); } else if (address == "/white/head/speed") { whiteHeadSpeed = tidalSpeed; whiteHead->setSpeed(whiteHeadSpeed); } else { Serial.println("dont know what to do with this OSC"); }; } else { Serial.println("dont mind me, heads' not part of this solo"); }; }); } void loop() { OscWiFi.update(); }