//EPS32_wrover_wifi-buckettruck
//Thanks to mukujii.sakura.ne.jp/esp1.html
//Thanks to www.freenove.com
//MX1508 MOTORA-M1 MX1508 MOTORB-M2
//RL1,RL2 - M3
#include <ESP32MX1508.h>
#define M1A 18 //MX1508 INT1
#define M1B 19 //MX1508 INT2
#define M2A 22 //MX1508 INT3
#define M2B 23 //MX1508 INT4
#define BU 4 //Bucket up
#define BD 5 //Bucket down
#define CH1 0
#define CH2 1
#define CH3 2
#define CH4 3
#define CH5 4
#define CH6 5
MX1508 motorA(M1A,M1B, CH1, CH2);
MX1508 motorB(M2A,M2B, CH3, CH4);
MX1508 motorC(BU,BD,CH5,CH6);
#include <WiFi.h>
const char* ssid = "";
const char* password = "";
const char html[] =
"<!DOCTYPE html><html lang='ja'><head><meta charset='UTF-8'>\
<style>input {font-size:16pt;margin:16px;width:160px;}\
div {font-size:32pt;color:blue;text-align:center;width:600px;border:medium solid black;}</style>\
<title>ESP32wrover WiFiCar</title></head>\
<body><div><p>WiFi_Controller</p>\
<form method='get'>\
<input type='submit' name='le' value='Left' />\
<input type='submit' name='fo' value='Forward' />\
<input type='submit' name='ri' value='Right' /><br>\
<input type='submit' name='bd' value='BucketDown' />\
<input type='submit' name='st' value='Stop' />\
<input type='submit' name='bu' value='BucketUp' /><br> \
<input type='submit' name='lb' value='LeftBack' />\
<input type='submit' name='ba' value='Back' />\
<input type='submit' name='rb' value='RightBack' /><br><br>\
</form></div></body></html>";
void Forward()
{
motorA.motorGo(200);
motorB.motorGo(230);
delay(100);
}
void Back()
{
motorA.motorRev(230);
motorB.motorRev(200);
delay(100);
}
void MotorStop()
{
motorA.motorStop();
motorB.motorStop();
motorC.motorStop();
}
void Right()
{
motorB.motorGo(200);
motorA.motorRev(200);
delay(50);
motorA.motorGo(200);
motorB.motorGo(230);
delay(100);
}
void Left()
{
motorA.motorGo(200);
motorB.motorRev(200);
delay(50);
motorA.motorGo(200);
motorB.motorGo(230);
delay(100);
}
void RightBack()
{
motorB.motorRev(200);
motorA.motorGo(200);
delay(50);
motorA.motorRev(230);
motorB.motorRev(200);
delay(100);
}
void LeftBack()
{
motorA.motorRev(200);
motorB.motorGo(200);
delay(50);
motorA.motorRev(230);
motorB.motorRev(200);
delay(100);
}
void BucketUp()
{
motorC.motorGo(200);
delay(1000);
}
void BucketDown()
{
motorC.motorRev(200);
delay(1000);
}
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop(){
WiFiClient client = server.available();
if (client) {
Serial.println("New Client.");
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
client.print(html);
client.println();
break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
if (currentLine.endsWith("GET /?fo")) {
Forward();
}
if (currentLine.endsWith("GET /?le")) {
Left();
}
if (currentLine.endsWith("GET /?ri")) {
Right();
}
if (currentLine.endsWith("GET /?ba")) {
Back();
}
if (currentLine.endsWith("GET /?lb")) {
LeftBack();
}
if (currentLine.endsWith("GET /?rb")) {
RightBack();
}
if (currentLine.endsWith("GET /?st")) {
MotorStop();
}
if (currentLine.endsWith("GET /?bu")) {
BucketUp();
}
if (currentLine.endsWith("GET /?bd")) {
BucketDown();
}
}
}
client.stop();
Serial.println("Client Disconnected.");
}
}
0 件のコメント:
コメントを投稿