Adding open and close,

make the page look a bit nicer.
This commit is contained in:
Joe Tretter
2022-09-14 09:51:28 -05:00
parent 5cd0c50a35
commit 97f6c01d7d

View File

@@ -38,7 +38,7 @@ int enable1Pin = 14;
const int freq = 30000;
const int pwmChannel = 0;
const int resolution = 8;
int motorSpeed = 220; // motor speed, max 355
int motorSpeed = 220; // motor speed, max 355
WebServer server(80);
@@ -132,7 +132,22 @@ const char* serverIndex =
"</script>";
const char* movePage =
"<h1><a href='/rev'>REV</a></h1> <h1><a href='/fwd'>FWD</a></h1>";
"<html>"
"<head>"
"<style type='text/css'>"
"button {"
"width: 100;"
"height: 100;"
"} "
"</style>"
"</head>"
"<body>"
"<a href='http://192.168.10.141/close'><button>CLOSE</button></a>"
"<a href='http://192.168.10.141/open'><button>OPEN</button></a>"
"<a href='http://192.168.10.141/rev'><button>REV</button></a>"
"<a href='http://192.168.10.141/fwd'><button>FWD</button></a>"
"</body>"
"</html>";
/*
* setup function
@@ -199,6 +214,30 @@ void setup(void) {
Serial.println("Motor Access");
server.send(200, "text/html", movePage);
});
server.on("/open", HTTP_GET, []() {
server.sendHeader("Connection", "close");
Serial.println("Opening");
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
delay(3000);
// Stop the DC motor
digitalWrite(motor1Pin2, LOW);
server.send(200, "text/html", movePage);
});
server.on("/close", HTTP_GET, []() {
server.sendHeader("Connection", "close");
Serial.println("Closing");
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
delay(3000);
// Stop the DC motor
digitalWrite(motor1Pin1, LOW);
server.send(200, "text/html", movePage);
});
server.on("/fwd", HTTP_GET, []() {
server.sendHeader("Connection", "close");
// Move the DC motor forward at maximum speed