SHARE
TWEET

Untitled

a guest Jun 25th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WiFi.h>
  2. #include <ESP32Servo.h>
  3.  
  4. #define DC_MOTOR_PIN1 25
  5. #define DC_MOTOR_PIN2 26
  6.  
  7. #define LEFT_CONTROL_PIN 32
  8. #define RIGHT_CONTROL_PIN 35
  9.  
  10. void loop()
  11. {
  12.  
  13.   WiFiClient client = server.available();
  14.  
  15.   if (client)
  16.   {                                
  17.     Serial.println("New Client.");
  18.     String currentLine = "";      
  19.     while (client.connected())
  20.     {
  21.       if (client.available())
  22.       {                      
  23.         char c = client.read();
  24.        
  25.         if (c == '\n')
  26.         {
  27.           if (currentLine.length() == 0)
  28.           {
  29.          
  30.             client.println("HTTP/1.1 200 OK");
  31.             client.println("Content-type:text/html");
  32.             client.println();
  33.        
  34.             client.println();
  35.             break;
  36.           }
  37.           else
  38.           {
  39.             currentLine = "";
  40.           }
  41.         }
  42.         else if (c != '\r')
  43.         {                  
  44.           currentLine += c;
  45.         }
  46.         if (currentLine.endsWith("GET /s"))
  47.         {
  48.           digitalWrite(DC_MOTOR_PIN1, LOW);
  49.           digitalWrite(DC_MOTOR_PIN2, LOW);
  50.           Serial.println();
  51.           Serial.println("Client entered /s");
  52.         }
  53.         if (currentLine.endsWith("GET /f"))
  54.         {
  55.          
  56.           digitalWrite(DC_MOTOR_PIN1, LOW);
  57.           digitalWrite(DC_MOTOR_PIN2, HIGH);
  58.           Serial.println();
  59.           Serial.println("Client entered /f");
  60.         }
  61.         if (currentLine.endsWith("GET /b"))
  62.         {
  63.          
  64.           digitalWrite(DC_MOTOR_PIN1, HIGH);
  65.           digitalWrite(DC_MOTOR_PIN2, LOW);
  66.           Serial.println();
  67.           Serial.println("Client entered /b");
  68.         }
  69.         if (currentLine.endsWith("GET /l"))
  70.         {
  71.           for (int i = servo.read(); i < 107; i += 3)
  72.           {
  73.             servo.write(i);
  74.             delay(70);
  75.           }
  76.           Serial.println();
  77.           Serial.println("Client entered /l");
  78.         }
  79.         if (currentLine.endsWith("GET /r"))
  80.         {
  81.           for (int i = servo.read(); i > 67; i -= 3)
  82.           {
  83.             servo.write(i);
  84.             delay(70);
  85.           }
  86.  
  87.           Serial.println();
  88.           Serial.println("Client entered /r");
  89.         }
  90.       }
  91.     }
  92.     client.stop();
  93.     Serial.println("Client Disconnected.");
  94.   }
  95. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top