Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.96 KB | None | 0 0
  1.  
  2.  
  3. #include <SPI.h>
  4. #include <Ethernet.h>
  5. #include <Servo.h>
  6. Servo myservo;  // create servo object to control a servo
  7. int R; //value to write to red
  8. int G;  //value to write to green
  9. int B;  //value to write to blue
  10.  
  11. byte mac[] = {
  12.   0x90, 0xA2, 0xDA, 0x0D, 0xFE, 0x59
  13. };
  14. IPAddress ip(192, 168, 0, 103);
  15.  
  16. // Initialize the Ethernet server library
  17. // with the IP address and port you want to use
  18. // (port 80 is default for HTTP):
  19. EthernetServer server(80);
  20.  
  21. String readString;
  22.  
  23. //////////////////////
  24.  
  25. void setup(){
  26.  
  27.   //start Ethernet
  28.   Ethernet.begin(mac, ip);
  29.   server.begin();
  30.  
  31.   //enable serial data print
  32.   Serial.begin(9600);
  33.  
  34.   Serial.println("RGB test"); // so I can keep track of what is loaded
  35. }
  36.  
  37. void loop(){
  38.   // Create a client connection
  39.   EthernetClient client = server.available();
  40.   if (client) {
  41.     while (client.connected()) {
  42.       if (client.available()) {
  43.         char c = client.read();
  44.  
  45.         //read char by char HTTP request
  46.         if (readString.length() < 100) {
  47.  
  48.           //store characters to string
  49.           readString += c;
  50.           //Serial.print(c);
  51.         }
  52.  
  53.         //if HTTP request has ended
  54.         if (c == '\n') {
  55.  
  56.           ///////////////
  57.           Serial.print(readString); //see what was captured
  58.  
  59.           //now output HTML data header
  60.  
  61.           client.println("HTTP/1.1 200 OK");
  62.           client.println("Content-Type: text/html");
  63.           client.println();
  64.  
  65.          
  66.  
  67.           client.println("<html>");
  68.           client.println("<body>");
  69.           client.println("<h2>Vpisi vrednosti RGB</h2>");
  70.           client.println("<form>");
  71.           client.println("  R:<br>");
  72.           client.println("<input type='text' name='r'>");
  73.           client.println("<br>");
  74.           client.println("G:<br>");
  75.           client.println("<input type='text' name='g'>");
  76.           client.println("<br>");
  77.           client.println("B:<br>");
  78.           client.println("<input type='text' name='b'>");
  79.           client.println("</form>");
  80.           client.println("</body>");
  81.           client.println("</html>");
  82.           client.println("<INPUT TYPE=SUBMIT NAME='submit' VALUE='Send RGB'>");
  83.  
  84.           client.println("</FORM>");
  85.  
  86.           client.println("<BR>");
  87.  
  88.           delay(1);
  89.           //stopping client
  90.           client.stop();
  91.  
  92.           /////////////////////
  93.           if (readString.length() >0) {
  94.            int rIdx = readString.indexOf("r");
  95.            int gIdx = readString.indexOf("g");
  96.            int bIdx = readString.indexOf("b");
  97.  
  98.            int R = readString.substring(rIdx + 2, gIdx - 1).toInt();
  99.            int G = readString.substring(gIdx + 2, bIdx - 1).toInt();
  100.            int B = readString.substring(bIdx + 2).toInt();
  101.            readString=""; //clears variable for new input  
  102.            Serial.println(R);  
  103.            Serial.println(G);  
  104.            Serial.println(B);  
  105.           }          
  106.         }
  107.       }
  108.     }
  109.   }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement