control
This commit is contained in:
parent
fb216b16fb
commit
9f4f42bab5
@ -18,19 +18,14 @@
|
|||||||
<h1 class="display-4">Water Heater Control</h1>
|
<h1 class="display-4">Water Heater Control</h1>
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<h2 id="currentSeconds" class="display-4">Number of Seconds: 5</h2>
|
<input type="range" id="temperature" name="temperature" min="90" max="120" onchange="setTemperature(this.value)">
|
||||||
<input type="range" id="seconds" name="seconds" min="1" max="9" onchange="setSeconds(this.value)">
|
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
<button type="button" class="btn btn-success btn-lg" id="toSlider">Set to [??]</button>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<button type="button" class="btn btn-primary btn-lg" id="down">Down</button>
|
|
||||||
<button type="button" class="btn btn-danger btn-lg" id="stop">Stop</button>
|
<button type="button" class="btn btn-danger btn-sm" id="initialize">Initialize to 90</button>
|
||||||
<button type="button" class="btn btn-primary btn-lg" id="up">Up</button>
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
<h2 id="currentAngle" class="display-4">Current Action: STOPPED</h2>
|
|
||||||
</div>
|
</div>
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
<script
|
<script
|
||||||
@ -40,61 +35,51 @@
|
|||||||
></script>
|
></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var seconds = 5;
|
var temperature = 90;
|
||||||
var currentTimeout = null;
|
var timer = null;
|
||||||
|
|
||||||
const DOWN_ANGLE = 150;
|
function setTemperature(temp) {
|
||||||
const STOP_ANGLE = 160;
|
temperature = temp;
|
||||||
const UP_ANGLE = 170;
|
$("#toSlider").text("Set Temperature: " + temperature)
|
||||||
|
console.log("Set Temperature: " + temperature);
|
||||||
function setSeconds(to) {
|
|
||||||
seconds = to;
|
|
||||||
$("#currentSeconds").text("Number of Seconds: " + seconds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function action(newTemperature) {
|
||||||
|
$("#toSlider").prop("disabled", true);
|
||||||
|
$("#temperature").prop("disabled", true);
|
||||||
|
console.log(newTemperature);
|
||||||
|
setTimeout(() => {
|
||||||
|
$("#toSlider").prop("disabled", false);
|
||||||
|
$("#temperature").prop("disabled", false);
|
||||||
|
|
||||||
function action(angle, direction) {
|
}, 3000);
|
||||||
console.log(angle, direction)
|
|
||||||
if (currentTimeout !== null) {
|
|
||||||
console.log(currentTimeout)
|
|
||||||
clearTimeout(currentTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
$.post("/angle", {
|
let rotations = newTemperature - 90; //base at 0;
|
||||||
angle: angle,
|
|
||||||
|
$.post("/setTemperature", {
|
||||||
|
newTemperature,
|
||||||
|
rotations,
|
||||||
});
|
});
|
||||||
$("#currentAngle").text("Current Action: " + direction);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (angle == STOP_ANGLE){
|
|
||||||
$("#down").prop("disabled", false)
|
|
||||||
$("#up").prop("disabled", false)
|
|
||||||
} else {
|
|
||||||
$("#down").prop("disabled", true)
|
|
||||||
$("#up").prop("disabled", true)
|
|
||||||
currentTimeout = setTimeout(() => {
|
|
||||||
action(STOP_ANGLE, "STOPPED");
|
|
||||||
}, seconds * 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
$("#down").on("click", () => {
|
$("#to90").on("click", () => {
|
||||||
action(DOWN_ANGLE, "decreasing")
|
action(90);
|
||||||
|
setTemperature(90);
|
||||||
|
document.getElementById("temperature").value = temperature;
|
||||||
});
|
});
|
||||||
$("#stop").on("click", () => {
|
$("#toSlider").on("click", () => {
|
||||||
action(STOP_ANGLE, "STOPPED")
|
action(temperature);
|
||||||
});
|
|
||||||
$("#up").on("click", () => {
|
|
||||||
action(UP_ANGLE, "increasing")
|
|
||||||
});
|
});
|
||||||
|
$("#initialize").on("click", () => {
|
||||||
|
$.post("/initialize");
|
||||||
|
})
|
||||||
|
|
||||||
action(STOP_ANGLE, "STOPPED")
|
|
||||||
|
|
||||||
setSeconds(seconds);
|
|
||||||
document.getElementById("seconds").value = seconds;
|
document.getElementById("temperature").value = temperature;
|
||||||
|
setTemperature(temperature);
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -25,8 +25,10 @@
|
|||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <AccelStepper.h>
|
#include <AccelStepper.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
|
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
|
||||||
|
bool initializing = false;
|
||||||
|
|
||||||
// ULN2003 Motor Driver Pins
|
// ULN2003 Motor Driver Pins
|
||||||
#define IN1 5
|
#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 *ssid = "TARDIS"; // replace with your SSID
|
||||||
const char *password = "EvangelionUnit-01"; // replace with your Password
|
const char *password = "EvangelionUnit-01"; // replace with your Password
|
||||||
const uint8_t servoPin = D1; // replace with servo pin
|
|
||||||
// Create Server instance
|
// Create Server instance
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// Attach Servo, start SPIFFS and Connect to WiFi
|
// Attach Servo, start SPIFFS and Connect to WiFi
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
stepper.setMaxSpeed(2000);
|
stepper.setMaxSpeed(3000);
|
||||||
stepper.setAcceleration(500);
|
stepper.setAcceleration(2500);
|
||||||
// set target position
|
// set target position
|
||||||
stepper.moveTo(0);
|
stepper.moveTo(0);
|
||||||
|
|
||||||
@ -74,26 +76,19 @@ void setup()
|
|||||||
request->send(SPIFFS, "/index.html", "text/html");
|
request->send(SPIFFS, "/index.html", "text/html");
|
||||||
});
|
});
|
||||||
|
|
||||||
/*server.on("/angle", HTTP_POST, [](AsyncWebServerRequest *request) {
|
|
||||||
String angle = request->arg("angle");
|
server.on("/setTemperature", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||||
Serial.println("Current Position: " + angle + "°");
|
int rotations = request->arg("rotations").toInt();
|
||||||
servo.write(angle.toInt());
|
double multiplier = 0.2; // TODO: find me out
|
||||||
request->send(200);
|
stepper.moveTo((multiplier * rotations) * stepsPerRevolution);
|
||||||
});*/
|
|
||||||
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);
|
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/ccw", HTTP_POST, [](AsyncWebServerRequest *request) {
|
|
||||||
Serial.println("cw");
|
//rotate a looot back to 90 F, as we cant go lower, so we over rotate then mark that as 0 POSITION
|
||||||
stepper.moveTo(- 2 * stepsPerRevolution);
|
server.on("/initialize", HTTP_POST, [](AsyncWebServerRequest *request) {
|
||||||
|
initializing = true;
|
||||||
|
stepper.moveTo(-10 * stepsPerRevolution);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -103,13 +98,18 @@ void setup()
|
|||||||
// Begin Server
|
// Begin Server
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
if (stepper.distanceToGo() == 0 && initializing){
|
||||||
|
initializing = false;
|
||||||
|
stepper.stop();
|
||||||
|
stepper.setCurrentPosition(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Current Position: ");
|
||||||
|
Serial.println(stepper.currentPosition());
|
||||||
stepper.run();
|
stepper.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user