daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <SPI.h>
  3. #include <Ethernet.h>
  4.  
  5. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  6. byte ip[] = { 192, 168, 1, 235 };
  7.      
  8. EthernetServer server(80);
  9.  
  10. String readString;
  11. int Pin = 6;
  12. int Pin1 = 7;
  13.  
  14. void setup(){
  15.  
  16.   pinMode(Pin, OUTPUT);
  17.   pinMode(Pin1, OUTPUT);
  18.  
  19.   Ethernet.begin(mac, ip);
  20.   server.begin();
  21. }
  22.  
  23. void loop(){
  24.   EthernetClient client = server.available();
  25.   if (client) {
  26.     while (client.connected()) {
  27.       if (client.available()) {
  28.         char c = client.read();
  29.  
  30.         if (readString.length() < 100) {
  31.           readString += c;            
  32.         }
  33.  
  34.         if (c == '\n') {
  35.           client.println("HTTP/1.1 200 OK");
  36.           client.println("Content-Type: text/html");
  37.           client.println();
  38.            
  39.           client.println("<HTML>");
  40.           client.println("<BODY>");
  41.           client.println("<H1>Acende LED</H1>");
  42.           client.println("<hr />");
  43.           client.println("<br />");
  44.            
  45.           client.println("<a href=\"/?ledon\">Ligar o led</a>");
  46.           client.println("<a href=\"/?ledoff\">Desligar o led</a><br />");  
  47.  
  48.           client.println("<a href=\"/?ledon1\">Ligar o led1</a>");
  49.           client.println("<a href=\"/?ledoff1\">Desligar o led1</a><br />");  
  50.            
  51.           client.println("</BODY>");
  52.           client.println("</HTML>");
  53.            
  54.           delay(1);
  55.           client.stop();
  56.            
  57.           if(readString.indexOf("?ledon") > 0)
  58.           {
  59.             digitalWrite(Pin, HIGH);
  60.           }
  61.           else {
  62.             if(readString.indexOf("?ledoff") > 0)
  63.             {
  64.               digitalWrite(Pin, LOW);
  65.  
  66.  
  67.           if(readString.indexOf("?ledon1") > 0)
  68.           {
  69.             digitalWrite(Pin1, HIGH);
  70.           }
  71.           else {
  72.             if(readString.indexOf("?ledoff1") > 0)
  73.             {
  74.               digitalWrite(Pin1, LOW);
  75.             }
  76.  
  77.             }
  78.           }
  79.           readString="";    
  80.         }
  81.       }
  82.     }
  83.   }
  84. }
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
 
Top