rename printers and return of one of the printers

master
vitrinekast 6 months ago
parent 2f7e9e7c28
commit ff9b5fda76

@ -1,25 +1,24 @@
#include <ArduinoOSCWiFi.h> #include <ArduinoOSCWiFi.h>
#include <Adafruit_MotorShield.h> #include <Adafruit_MotorShield.h>
const int C_BLACKFEED = 3; const int C_FREEDFEED = 1;
const int C_BLACKHEAD = 4; const int C_FREEDHEAD = 2;
const int C_WRIGHTFEED = 3;
const int C_WRIGHTHEAD = 4;
const int recv_port = 10000; const int recv_port = 10000;
const int send_port = 6060; const int send_port = 6060;
int blackHeadSpeed = 150; int wrightHeadSpeed = 150;
int blackFeedSpeed = 150; int wrightFeedSpeed = 150;
int freedHeadSpeed = 150;
uint8_t stepperType = SINGLE; int freedFeedSpeed = 150;
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* wrightHead = AFMS.getMotor(C_WRIGHTHEAD);
Adafruit_DCMotor* blackFeed = AFMS.getMotor(C_BLACKFEED); Adafruit_DCMotor* wrightFeed = AFMS.getMotor(C_WRIGHTFEED);
Adafruit_DCMotor* freedHead = AFMS.getMotor(C_FREEDHEAD);
// 48 = steps count based on revolution of the motor (7.5degree/step motor has 360/7.5 = 48), 2 = motor number Adafruit_DCMotor* freedFeed = AFMS.getMotor(C_FREEDFEED);
Adafruit_StepperMotor* stepper = AFMS.getStepper(stepperRPM, 1);
// customise as needed // customise as needed
const char* ssid = "XPUB"; const char* ssid = "XPUB";
@ -57,86 +56,103 @@ 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. wrightHead->setSpeed(wrightHeadSpeed);
stepper->release(); wrightHead->run(RELEASE);
blackHead->setSpeed(blackHeadSpeed); wrightFeed->setSpeed(wrightFeedSpeed);
blackHead->run(RELEASE); wrightFeed->run(RELEASE);
blackFeed->setSpeed(blackFeedSpeed); wrightHead->setSpeed(freedHeadSpeed);
blackFeed->run(RELEASE); freedHead->run(RELEASE);
freedFeed->setSpeed(freedFeedSpeed);
freedFeed->run(RELEASE);
OscWiFi.subscribe(recv_port, "/stopall", [](const OscMessage& m) { OscWiFi.subscribe(recv_port, "/stopall", [](const OscMessage& m) {
blackFeed->run(RELEASE); wrightFeed->run(RELEASE);
blackHead->run(RELEASE); wrightHead->run(RELEASE);
stepper->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); float tidalSpeed = m.arg<float>(0);
String address = m.address(); String address = m.address();
// Serial.println(address); // Serial.println(address);
Serial.println(address); Serial.println(address);
if (address == "/black/feed/f") { if (address == "/wright/feed/f") {
blackFeed->run(FORWARD); wrightFeed->run(FORWARD);
} else if (address == "/black/feed/b") { } else if (address == "/wright/feed/b") {
blackFeed->run(BACKWARD); wrightFeed->run(BACKWARD);
} else if (address == "/black/feed/r") { } else if (address == "/wright/feed/r") {
blackFeed->run(RELEASE); wrightFeed->run(RELEASE);
} else if (address == "/black/feed/speed") { } else if (address == "/wright/feed/speed") {
blackFeedSpeed = tidalSpeed; wrightFeedSpeed = tidalSpeed;
blackFeed->setSpeed(blackFeedSpeed); wrightFeed->setSpeed(wrightFeedSpeed);
} else { } else {
Serial.println("dont know what to do with this OSC"); 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); float tidalSpeed = m.arg<float>(0);
String address = m.address(); String address = m.address();
// Serial.println(address); // Serial.println(address);
Serial.println(address); Serial.println(address);
if (address == "/black/head/f") { if (address == "/wright/head/f") {
blackHead->run(FORWARD); wrightHead->run(FORWARD);
} else if (address == "/black/head/b") { } else if (address == "/wright/head/b") {
blackHead->run(BACKWARD); wrightHead->run(BACKWARD);
} else if (address == "/black/head/r") { } else if (address == "/wright/head/r") {
blackHead->run(RELEASE); wrightHead->run(RELEASE);
} else if (address == "/black/head/speed") { } else if (address == "/wright/head/speed") {
blackHeadSpeed = tidalSpeed; wrightHeadSpeed = tidalSpeed;
blackHead->setSpeed(blackHeadSpeed); wrightHead->setSpeed(wrightHeadSpeed);
} else { } else {
Serial.println("dont know what to do with this OSC"); 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(); String address = m.address();
// Serial.println(address);
Serial.println(address); Serial.println(address);
if (address == "/stepper/f") { if (address == "/freed/feed/f") {
stepper->step(stepperSteps, FORWARD, stepperType); freedFeed->run(FORWARD);
} else if (address == "/stepper/b") { } else if (address == "/freed/feed/b") {
stepper->step(stepperSteps, BACKWARD, stepperType); freedFeed->run(BACKWARD);
} else if (address == "/stepper/r") { } else if (address == "/freed/feed/r") {
stepper->release(); freedFeed->run(RELEASE);
} else if (address == "/stepper/mode") { } else if (address == "/freed/feed/speed") {
stepperType = m.arg<int>(0); freedFeedSpeed = tidalSpeed;
Serial.print("setting step type to"); freedFeed->setSpeed(freedFeedSpeed);
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");
}; };
}); });
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() { void loop() {

Loading…
Cancel
Save