From df7f56bc963c4734d7b79b0ca2cf52d3f7c9f562 Mon Sep 17 00:00:00 2001 From: alicegetm <aliceg3@illinois.edu> Date: Sun, 27 Nov 2022 16:58:02 -0600 Subject: [PATCH] button controls motors & pressure --- arduino_code/test_webpage_sensors.ino | 35 +++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/arduino_code/test_webpage_sensors.ino b/arduino_code/test_webpage_sensors.ino index 4bb1bc2..db68eb8 100644 --- a/arduino_code/test_webpage_sensors.ino +++ b/arduino_code/test_webpage_sensors.ino @@ -1,6 +1,5 @@ /********* - Rui Santos - Complete project details at https://randomnerdtutorials.com/esp8266-dht11dht22-temperature-and-humidity-web-server-with-arduino-ide/ + https://randomnerdtutorials.com/esp32-async-web-server-espasyncwebserver-library/ *********/ // Import required libraries @@ -9,6 +8,8 @@ #include <ESPAsyncWebServer.h> #include <AsyncTCP.h> #include <Stepper.h> +#include <AccelStepper.h> +#include <MultiStepper.h> // Replace with your network credentials const char* ssid = "Connectify-ESP32 Boot"; @@ -28,6 +29,7 @@ const char* input_parameter2 = "state"; #define PRESSURE2GOAL 2034 Stepper motor(200, motorIN1, motorIN2, motorIN3, motorIN4); +//AccelStepper motor(AccelStepper::FULL4WIRE, motorIN1, motorIN2, motorIN3, motorIN4); // current temperature & humidity, updated in loop() int pressure1 = 0.0; @@ -126,7 +128,7 @@ setInterval(function ( ) { }; xhttp.open("GET", "/pressure1", true); xhttp.send(); -}, 0.1 ) ; +}, 1000 ) ; setInterval(function ( ) { var xhttp = new XMLHttpRequest(); @@ -137,7 +139,7 @@ setInterval(function ( ) { }; xhttp.open("GET", "/pressure1status", true); xhttp.send(); -}, 0.1 ) ; +}, 1000 ) ; setInterval(function ( ) { var xhttp = new XMLHttpRequest(); @@ -148,7 +150,7 @@ setInterval(function ( ) { }; xhttp.open("GET", "/pressure2", true); xhttp.send(); -}, 0.1 ) ; +}, 1000 ) ; setInterval(function ( ) { var xhttp = new XMLHttpRequest(); @@ -159,7 +161,7 @@ setInterval(function ( ) { }; xhttp.open("GET", "/pressure2status", true); xhttp.send(); -}, 0.1 ) ; +}, 1000 ) ; setInterval(function ( ) { var xhttp = new XMLHttpRequest(); @@ -170,7 +172,7 @@ setInterval(function ( ) { }; xhttp.open("GET", "/motor1status", true); xhttp.send(); -}, 0.1 ) ; +}, 1000 ) ; </script> </html>)rawliteral"; @@ -262,6 +264,25 @@ void setup(){ Serial.print(inputMessage1); Serial.print(" - Set to: "); Serial.println(inputMessage2); + + if (inputMessage2.toInt() == 1){ + motor1status="running!!!"; // doesn't work idk why +// motor.setSpeed(120); +// motor.setCurrentPosition(0); +// motor.setAcceleration(10); +// +// motor.moveTo(2000); +// +// while(motor.distanceToGo() <= 1000) { +// motor.setSpeed(80); +// motor.runToPosition(); +// } + motor.setSpeed(60); + motor.step(500); + motor.setSpeed(0); +// motor1status = "motor stop"; + } + request->send(200, "text/plain", "OK"); }); -- GitLab