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, "/wright/feed/*", [](const OscMessage& m) {
float tidalSpeed = m.arg<float>(0);
String address = m.address();
// Serial.println(address);
Serial.println(address);
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/feed/*", [](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/feed/f") { if (address == "/wright/head/f") {
blackFeed->run(FORWARD); wrightHead->run(FORWARD);
} else if (address == "/black/feed/b") { } else if (address == "/wright/head/b") {
blackFeed->run(BACKWARD); wrightHead->run(BACKWARD);
} else if (address == "/black/feed/r") { } else if (address == "/wright/head/r") {
blackFeed->run(RELEASE); wrightHead->run(RELEASE);
} else if (address == "/black/feed/speed") { } else if (address == "/wright/head/speed") {
blackFeedSpeed = tidalSpeed; wrightHeadSpeed = tidalSpeed;
blackFeed->setSpeed(blackFeedSpeed); 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, "/black/head/*", [](const OscMessage& m) { OscWiFi.subscribe(recv_port, "/freed/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/head/f") { if (address == "/freed/feed/f") {
blackHead->run(FORWARD); freedFeed->run(FORWARD);
} else if (address == "/black/head/b") { } else if (address == "/freed/feed/b") {
blackHead->run(BACKWARD); freedFeed->run(BACKWARD);
} else if (address == "/black/head/r") { } else if (address == "/freed/feed/r") {
blackHead->run(RELEASE); freedFeed->run(RELEASE);
} else if (address == "/black/head/speed") { } else if (address == "/freed/feed/speed") {
blackHeadSpeed = tidalSpeed; freedFeedSpeed = tidalSpeed;
blackHead->setSpeed(blackHeadSpeed); freedFeed->setSpeed(freedFeedSpeed);
} 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/head/*", [](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/head/f") {
stepper->step(stepperSteps, FORWARD, stepperType); freedHead->run(FORWARD);
} else if (address == "/stepper/b") { } else if (address == "/freed/head/b") {
stepper->step(stepperSteps, BACKWARD, stepperType); freedHead->run(BACKWARD);
} else if (address == "/stepper/r") { } else if (address == "/freed/head/r") {
stepper->release(); freedHead->run(RELEASE);
} else if (address == "/stepper/mode") { } else if (address == "/freed/head/speed") {
stepperType = m.arg<int>(0); freedHeadSpeed = tidalSpeed;
Serial.print("setting step type to"); freedHead->setSpeed(freedHeadSpeed);
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");
}; };
}); });
} }
void loop() { void loop() {

Loading…
Cancel
Save