rename printers and return of one of the printers

master
vitrinekast 7 months ago
parent 2f7e9e7c28
commit ff9b5fda76

@ -1,25 +1,24 @@
#include <ArduinoOSCWiFi.h>
#include <Adafruit_MotorShield.h>
const int C_BLACKFEED = 3;
const int C_BLACKHEAD = 4;
const int C_FREEDFEED = 1;
const int C_FREEDHEAD = 2;
const int C_WRIGHTFEED = 3;
const int C_WRIGHTHEAD = 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;
int wrightHeadSpeed = 150;
int wrightFeedSpeed = 150;
int freedHeadSpeed = 150;
int freedFeedSpeed = 150;
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor* blackHead = AFMS.getMotor(C_BLACKHEAD);
Adafruit_DCMotor* blackFeed = AFMS.getMotor(C_BLACKFEED);
// 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);
Adafruit_DCMotor* wrightHead = AFMS.getMotor(C_WRIGHTHEAD);
Adafruit_DCMotor* wrightFeed = AFMS.getMotor(C_WRIGHTFEED);
Adafruit_DCMotor* freedHead = AFMS.getMotor(C_FREEDHEAD);
Adafruit_DCMotor* freedFeed = AFMS.getMotor(C_FREEDFEED);
// customise as needed
const char* ssid = "XPUB";
@ -57,86 +56,103 @@ void setup() {
Serial.print("ESP CPU Frequency in MHz: ");
Serial.println(ESP.getCpuFreqMHz());
stepper->setSpeed(stepperRPM); // RPM = is how many revolutions per minute you want the stepper to turn.
stepper->release();
blackHead->setSpeed(blackHeadSpeed);
blackHead->run(RELEASE);
blackFeed->setSpeed(blackFeedSpeed);
blackFeed->run(RELEASE);
wrightHead->setSpeed(wrightHeadSpeed);
wrightHead->run(RELEASE);
wrightFeed->setSpeed(wrightFeedSpeed);
wrightFeed->run(RELEASE);
wrightHead->setSpeed(freedHeadSpeed);
freedHead->run(RELEASE);
freedFeed->setSpeed(freedFeedSpeed);
freedFeed->run(RELEASE);
OscWiFi.subscribe(recv_port, "/stopall", [](const OscMessage& m) {
blackFeed->run(RELEASE);
blackHead->run(RELEASE);
stepper->release();
wrightFeed->run(RELEASE);
wrightHead->run(RELEASE);
freedFeed->run(RELEASE);
freedHead->run(RELEASE);
});
OscWiFi.subscribe(recv_port, "/black/feed/*", [](const OscMessage& m) {
OscWiFi.subscribe(recv_port, "/wright/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);
if (address == "/wright/feed/f") {
wrightFeed->run(FORWARD);
} else if (address == "/wright/feed/b") {
wrightFeed->run(BACKWARD);
} else if (address == "/wright/feed/r") {
wrightFeed->run(RELEASE);
} else if (address == "/wright/feed/speed") {
wrightFeedSpeed = tidalSpeed;
wrightFeed->setSpeed(wrightFeedSpeed);
} else {
Serial.println("dont know what to do with this OSC");
};
});
OscWiFi.subscribe(recv_port, "/black/head/*", [](const OscMessage& m) {
OscWiFi.subscribe(recv_port, "/wright/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);
if (address == "/wright/head/f") {
wrightHead->run(FORWARD);
} else if (address == "/wright/head/b") {
wrightHead->run(BACKWARD);
} else if (address == "/wright/head/r") {
wrightHead->run(RELEASE);
} else if (address == "/wright/head/speed") {
wrightHeadSpeed = tidalSpeed;
wrightHead->setSpeed(wrightHeadSpeed);
} else {
Serial.println("dont know what to do with this OSC");
};
});
OscWiFi.subscribe(recv_port, "/stepper/*", [](const OscMessage& m) {
OscWiFi.subscribe(recv_port, "/freed/feed/*", [](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0);
String address = m.address();
// Serial.println(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/mode") {
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);
if (address == "/freed/feed/f") {
freedFeed->run(FORWARD);
} else if (address == "/freed/feed/b") {
freedFeed->run(BACKWARD);
} else if (address == "/freed/feed/r") {
freedFeed->run(RELEASE);
} else if (address == "/freed/feed/speed") {
freedFeedSpeed = tidalSpeed;
freedFeed->setSpeed(freedFeedSpeed);
} else {
Serial.println("dont know what to do with this OSC");
};
});
OscWiFi.subscribe(recv_port, "/freed/head/*", [](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0);
String address = m.address();
// Serial.println(address);
Serial.println(address);
if (address == "/freed/head/f") {
freedHead->run(FORWARD);
} else if (address == "/freed/head/b") {
freedHead->run(BACKWARD);
} else if (address == "/freed/head/r") {
freedHead->run(RELEASE);
} else if (address == "/freed/head/speed") {
freedHeadSpeed = tidalSpeed;
freedHead->setSpeed(freedHeadSpeed);
} else {
Serial.println("dont know what to do with this OSC");
};
});
}
void loop() {

Loading…
Cancel
Save