remove white printer, reformat code, include stepper motor, add additional stepper OSC messages

master
vitrinekast 6 months ago
parent d36e541625
commit 62bdbeb2fd

@ -1,17 +1,25 @@
#include <ArduinoOSCWiFi.h> #include <ArduinoOSCWiFi.h>
#include <Adafruit_MotorShield.h> #include <Adafruit_MotorShield.h>
const int C_WHITEHEAD = 1;
const int C_WHITEFEED = 2;
const int C_BLACKFEED = 3; const int C_BLACKFEED = 3;
const int C_BLACKHEAD = 4; const int C_BLACKHEAD = 4;
const int recv_port = 10000;
const int send_port = 6060;
int blackHeadSpeed = 150;
int blackFeedSpeed = 150;
uint8_t stepperType = SINGLE;
int stepperSteps = 100;
int stepperRPM = 10;
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor* blackHead = AFMS.getMotor(C_BLACKHEAD); Adafruit_DCMotor* blackHead = AFMS.getMotor(C_BLACKHEAD);
Adafruit_DCMotor* blackFeed = AFMS.getMotor(C_BLACKFEED); Adafruit_DCMotor* blackFeed = AFMS.getMotor(C_BLACKFEED);
Adafruit_DCMotor* whiteFeed = AFMS.getMotor(C_WHITEFEED);
Adafruit_DCMotor* whiteHead = AFMS.getMotor(C_WHITEHEAD); // 48 = steps count based on revolution of the motor (7.5degree/step motor has 360/7.5 = 48), 2 = motor number
Adafruit_StepperMotor* stepper = AFMS.getStepper(stepperRPM, 1);
// customise as needed // customise as needed
const char* ssid = "XPUB"; const char* ssid = "XPUB";
@ -21,26 +29,6 @@ const IPAddress ip(192, 168, 1, 171);
const IPAddress gateway(192, 168, 1, 1); const IPAddress gateway(192, 168, 1, 1);
const IPAddress subnet(255, 255, 255, 0); 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() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -56,7 +44,7 @@ void setup() {
WiFi.localIP(); WiFi.localIP();
}; };
if (!AFMS.begin()) { # here for pwm if (!AFMS.begin()) { // here for pwm
Serial.println("Could not find Motor Shield. Check wiring."); Serial.println("Could not find Motor Shield. Check wiring.");
while (1) while (1)
; ;
@ -69,31 +57,24 @@ void setup() {
Serial.print("ESP CPU Frequency in MHz: "); Serial.print("ESP CPU Frequency in MHz: ");
Serial.println(ESP.getCpuFreqMHz()); Serial.println(ESP.getCpuFreqMHz());
stepper->setSpeed(stepperRPM); // RPM = is how many revolutions per minute you want the stepper to turn.
whiteHead->setSpeed(whiteHeadSpeed); stepper->release();
whiteHead->run(RELEASE);
blackHead->setSpeed(blackHeadSpeed); blackHead->setSpeed(blackHeadSpeed);
blackHead->run(RELEASE); blackHead->run(RELEASE);
whiteFeed->setSpeed(whiteFeedSpeed);
whiteFeed->run(RELEASE);
blackFeed->setSpeed(blackFeedSpeed); blackFeed->setSpeed(blackFeedSpeed);
blackFeed->run(RELEASE); blackFeed->run(RELEASE);
OscWiFi.subscribe(recv_port, "/stopall", OscWiFi.subscribe(recv_port, "/stopall", [](const OscMessage& m) {
[](const OscMessage& m) {
blackFeed->run(RELEASE); blackFeed->run(RELEASE);
blackHead->run(RELEASE); blackHead->run(RELEASE);
whiteFeed->run(RELEASE); stepper->release();
whiteHead->run(RELEASE);
}); });
OscWiFi.subscribe(recv_port, "/black/feed/*", OscWiFi.subscribe(recv_port, "/black/feed/*", [](const OscMessage& m) {
[](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0); float tidalSpeed = m.arg<float>(0);
String address = m.address(); String address = m.address();
// Serial.println(address); // Serial.println(address);
if (STATE_SOLO == C_BLACKFEED || STATE_SOLO == 0) {
Serial.println(address); Serial.println(address);
if (address == "/black/feed/f") { if (address == "/black/feed/f") {
blackFeed->run(FORWARD); blackFeed->run(FORWARD);
@ -107,43 +88,13 @@ void setup() {
} else { } else {
Serial.println("dont know what to do with this OSC"); 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/*", OscWiFi.subscribe(recv_port, "/black/head/*", [](const OscMessage& m) {
[](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0); float tidalSpeed = m.arg<float>(0);
String address = m.address(); String address = m.address();
// Serial.println(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<float>(0);
String address = m.address();
// Serial.println(address);
if (STATE_SOLO == C_BLACKHEAD || STATE_SOLO == 0) {
Serial.println(address); Serial.println(address);
if (address == "/black/head/f") { if (address == "/black/head/f") {
blackHead->run(FORWARD); blackHead->run(FORWARD);
@ -157,40 +108,37 @@ void setup() {
} else { } else {
Serial.println("dont know what to do with this OSC"); 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/*", OscWiFi.subscribe(recv_port, "/stepper/*", [](const OscMessage& m) {
[](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0);
String address = m.address(); String address = m.address();
// Serial.println(address);
if (STATE_SOLO == C_WHITEHEAD || STATE_SOLO == 0) {
Serial.println(address); Serial.println(address);
if (address == "/white/head/f") { if (address == "/stepper/f") {
whiteHead->run(FORWARD); stepper->step(stepperSteps, FORWARD, stepperType);
} else if (address == "/white/head/b") { } else if (address == "/stepper/b") {
whiteHead->run(BACKWARD); stepper->step(stepperSteps, BACKWARD, stepperType);
} else if (address == "/white/head/r") { } else if (address == "/stepper/r") {
whiteHead->run(RELEASE); stepper->release();
} else if (address == "/white/head/speed") { } else if (address == "/stepper/type") {
whiteHeadSpeed = tidalSpeed; stepperType = m.arg<int>(0);
whiteHead->setSpeed(whiteHeadSpeed); Serial.print("setting step type to");
Serial.println(stepperType);
} else if (address == "/stepper/steps") {
stepperSteps = m.arg<float>(0);
Serial.print("setting steps");
Serial.println(stepperSteps);
} else if (address == "/stepper/rpm") {
stepperRPM = m.arg<float>(0);
Serial.print("setting RPM");
Serial.println(stepperRPM);
stepper->setSpeed(stepperRPM);
} else { } else {
Serial.println("dont know what to do with this OSC"); Serial.println("dont know what to do with this OSC");
}; };
} else {
Serial.println("dont mind me, heads' not part of this solo");
};
}); });
} }
void loop() { void loop() {
OscWiFi.update(); OscWiFi.update();
} }

Loading…
Cancel
Save