Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <ESP32Servo.h>
- #define DC_MOTOR_PIN1 25
- #define DC_MOTOR_PIN2 26
- #define LEFT_CONTROL_PIN 32
- #define RIGHT_CONTROL_PIN 35
- void loop()
- {
- WiFiClient client = server.available();
- if (client)
- {
- Serial.println("New Client.");
- String currentLine = "";
- while (client.connected())
- {
- if (client.available())
- {
- char c = client.read();
- if (c == '\n')
- {
- if (currentLine.length() == 0)
- {
- client.println("HTTP/1.1 200 OK");
- client.println("Content-type:text/html");
- client.println();
- client.println();
- break;
- }
- else
- {
- currentLine = "";
- }
- }
- else if (c != '\r')
- {
- currentLine += c;
- }
- if (currentLine.endsWith("GET /s"))
- {
- digitalWrite(DC_MOTOR_PIN1, LOW);
- digitalWrite(DC_MOTOR_PIN2, LOW);
- Serial.println();
- Serial.println("Client entered /s");
- }
- if (currentLine.endsWith("GET /f"))
- {
- digitalWrite(DC_MOTOR_PIN1, LOW);
- digitalWrite(DC_MOTOR_PIN2, HIGH);
- Serial.println();
- Serial.println("Client entered /f");
- }
- if (currentLine.endsWith("GET /b"))
- {
- digitalWrite(DC_MOTOR_PIN1, HIGH);
- digitalWrite(DC_MOTOR_PIN2, LOW);
- Serial.println();
- Serial.println("Client entered /b");
- }
- if (currentLine.endsWith("GET /l"))
- {
- for (int i = servo.read(); i < 107; i += 3)
- {
- servo.write(i);
- delay(70);
- }
- Serial.println();
- Serial.println("Client entered /l");
- }
- if (currentLine.endsWith("GET /r"))
- {
- for (int i = servo.read(); i > 67; i -= 3)
- {
- servo.write(i);
- delay(70);
- }
- Serial.println();
- Serial.println("Client entered /r");
- }
- }
- }
- client.stop();
- Serial.println("Client Disconnected.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement