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 <Adafruit_MotorShield.h>
const int C_WHITEHEAD = 1;
const int C_WHITEFEED = 2;
const int C_BLACKFEED = 3;
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_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);
// 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
const char* ssid = "XPUB";
@ -21,26 +29,6 @@ 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);
@ -56,7 +44,7 @@ void setup() {
WiFi.localIP();
};
if (!AFMS.begin()) { # here for pwm
if (!AFMS.begin()) { // here for pwm
Serial.println("Could not find Motor Shield. Check wiring.");
while (1)
;
@ -69,128 +57,88 @@ void setup() {
Serial.print("ESP CPU Frequency in MHz: ");
Serial.println(ESP.getCpuFreqMHz());
whiteHead->setSpeed(whiteHeadSpeed);
whiteHead->run(RELEASE);
stepper->setSpeed(stepperRPM); // RPM = is how many revolutions per minute you want the stepper to turn.
stepper->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<float>(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<float>(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<float>(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<float>(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");
};
});
OscWiFi.subscribe(recv_port, "/stopall", [](const OscMessage& m) {
blackFeed->run(RELEASE);
blackHead->run(RELEASE);
stepper->release();
});
OscWiFi.subscribe(recv_port, "/black/feed/*", [](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0);
String address = m.address();
// Serial.println(address);
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");
};
});
OscWiFi.subscribe(recv_port, "/black/head/*", [](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0);
String address = m.address();
// Serial.println(address);
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");
};
});
OscWiFi.subscribe(recv_port, "/stepper/*", [](const OscMessage& m) {
String address = m.address();
Serial.println(address);
if (address == "/stepper/f") {
stepper->step(stepperSteps, FORWARD, stepperType);
} else if (address == "/stepper/b") {
stepper->step(stepperSteps, BACKWARD, stepperType);
} else if (address == "/stepper/r") {
stepper->release();
} else if (address == "/stepper/type") {
stepperType = m.arg<int>(0);
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 {
Serial.println("dont know what to do with this OSC");
};
});
}
void loop() {
OscWiFi.update();
}

Loading…
Cancel
Save