From 9f4f42bab526ecb42c0d2f5241c9c2b877745be9 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Tue, 1 Nov 2022 01:08:29 -0400 Subject: [PATCH] control --- data/index.html | 85 ++++++++++++++++++++----------------------------- frank_tank.ino | 52 +++++++++++++++--------------- 2 files changed, 61 insertions(+), 76 deletions(-) diff --git a/data/index.html b/data/index.html index 44a9756..a2f5aa4 100644 --- a/data/index.html +++ b/data/index.html @@ -18,19 +18,14 @@

Water Heater Control


-

Number of Seconds: 5

- +
+

- - - -
-
-
-

Current Action: STOPPED

+ + diff --git a/frank_tank.ino b/frank_tank.ino index a1ca69c..bb28386 100644 --- a/frank_tank.ino +++ b/frank_tank.ino @@ -25,8 +25,10 @@ #include #include #include +#include const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution +bool initializing = false; // ULN2003 Motor Driver Pins #define IN1 5 @@ -39,15 +41,15 @@ AccelStepper stepper(AccelStepper::HALF4WIRE, IN1, IN3, IN2, IN4); const char *ssid = "TARDIS"; // replace with your SSID const char *password = "EvangelionUnit-01"; // replace with your Password -const uint8_t servoPin = D1; // replace with servo pin + // Create Server instance AsyncWebServer server(80); void setup() { // Attach Servo, start SPIFFS and Connect to WiFi Serial.begin(115200); - stepper.setMaxSpeed(2000); - stepper.setAcceleration(500); + stepper.setMaxSpeed(3000); + stepper.setAcceleration(2500); // set target position stepper.moveTo(0); @@ -74,26 +76,19 @@ void setup() request->send(SPIFFS, "/index.html", "text/html"); }); - /*server.on("/angle", HTTP_POST, [](AsyncWebServerRequest *request) { - String angle = request->arg("angle"); - Serial.println("Current Position: " + angle + "°"); - servo.write(angle.toInt()); - request->send(200); - });*/ - server.on("/stop", HTTP_POST, [](AsyncWebServerRequest *request) { - Serial.println("stopping"); - stepper.stop(); - request->send(200); - }); - server.on("/cw", HTTP_POST, [](AsyncWebServerRequest *request) { - Serial.println("cw"); - stepper.moveTo(2 * stepsPerRevolution); + + server.on("/setTemperature", HTTP_POST, [](AsyncWebServerRequest *request) { + int rotations = request->arg("rotations").toInt(); + double multiplier = 0.2; // TODO: find me out + stepper.moveTo((multiplier * rotations) * stepsPerRevolution); request->send(200); }); - server.on("/ccw", HTTP_POST, [](AsyncWebServerRequest *request) { - Serial.println("cw"); - stepper.moveTo(- 2 * stepsPerRevolution); + + //rotate a looot back to 90 F, as we cant go lower, so we over rotate then mark that as 0 POSITION + server.on("/initialize", HTTP_POST, [](AsyncWebServerRequest *request) { + initializing = true; + stepper.moveTo(-10 * stepsPerRevolution); request->send(200); }); @@ -103,13 +98,18 @@ void setup() // Begin Server server.begin(); } + + + void loop() { + if (stepper.distanceToGo() == 0 && initializing){ + initializing = false; + stepper.stop(); + stepper.setCurrentPosition(0); + } + + Serial.print("Current Position: "); + Serial.println(stepper.currentPosition()); stepper.run(); } - - - - - -