Advertisement
Guest User

Untitled

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