Advertisement
RuiViana

New HTML Liga LED

Dec 14th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. //=============================================================================DECLARANDO E CONFIGURANDO ETHERNET=============================================================//
  2. #include <SPI.h>
  3. #include <Ethernet.h>
  4. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  5. byte ip[] = { 192, 168, 0, 5 };
  6. EthernetServer server(80);
  7. String readString;
  8. //===============================================================================DECLARANDO AS VARIAVEIS GLOBAIS==============================================================//
  9. boolean Led;
  10.  
  11. //================================================================================ROTINA DE SETUP CONFIGURAÇÕES===============================================================//
  12. void setup(){
  13.  
  14. pinMode(7, OUTPUT);
  15. // pinMode(26, OUTPUT);
  16. pinMode(2,INPUT);
  17. Ethernet.begin(mac, ip);
  18. server.begin();
  19. Serial.begin(9600);
  20. }
  21. //=====================================================================================LOOP INFINITO PROGRAMA=================================================================//
  22. void loop(){
  23. EthernetClient client = server.available();
  24. if (client) {
  25. while (client.connected()) {
  26. if (client.available()) {
  27. char c = client.read();
  28.  
  29. if (readString.length() < 100) {
  30. readString += c;
  31. }
  32.  
  33. if (c == '\n') {
  34.  
  35. client.println("HTTP/1.1 200 OK");
  36. client.println("Content-Type: text/html");
  37. client.println("Refresh: 2"); //ATUALIZA O HTML DE 2 EM 2 SEGUNDOS
  38. client.println();
  39.  
  40. client.println("<HTML>");
  41. client.println("<BODY>");
  42. client.println("<TITLE>SUPERVISORIO</TITLE>");
  43. client.println("<H1><center>SUPERVISORIO.</center></H1>");
  44. client.println("<hr />");
  45. client.println("<br />");
  46.  
  47. client.println("<table border='1' width='17%'>");
  48. client.println("<tr>");
  49. client.println("<td width='103' align='center'>LED 1</td>");
  50. if (digitalRead(7)==1)
  51. client.println("<td align='center'>ON</td>");
  52. else
  53. client.println("<td align='center'>OFF</td>");
  54. client.println("</tr>");
  55. client.println("</table>");
  56.  
  57. if (digitalRead(7)==HIGH)
  58. {
  59. client.println("<a href=\"/?ledoff\"\">Desligar o led</a><br />");
  60. }
  61. else
  62. {
  63. client.println("<a href=\"/?ledon\"\">Ligar o led</a>");
  64. }
  65. /*
  66. client.println("<a href=\"/?ledon\"\">Ligar o led</a>");
  67. client.println("<br />");
  68. client.println("<a href=\"/?ledoff\"\">Desligar o led</a><br />");*/
  69.  
  70. client.println("</BODY>");
  71. client.println("</HTML>");
  72.  
  73. delay(1);
  74. client.stop();
  75.  
  76. if(readString.indexOf("?ledon") > 0)
  77. {
  78. digitalWrite(7, HIGH);
  79. }
  80. else {
  81. if(readString.indexOf("?ledoff") > 0)
  82. {
  83. digitalWrite(7, LOW);
  84. }
  85. }
  86. readString="";
  87. }
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement