Advertisement
Guest User

DIOGO AS PARTES QUE MUDEI TA ESCRITO : EU QUE FIZ

a guest
Sep 3rd, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. //Programa : Arduino Ethernet Shield W5100 e HC-SR04
  2. //Alteracoes e adaptacoes : FILIPEFLOP
  3. //
  4. //Baseado no programa exemplo de
  5. //by David A. Mellis e Tom Igoe
  6.  
  7.  
  8. #include <SPI.h>
  9. #include <Ethernet.h>
  10.  
  11. //Define os parametros para o sensor ultrasonico HC-SR04
  12. #define PINO_TRIGGER 13 //Porta ligada ao pino Trigger do sensor
  13.  
  14. //Inicializa o sensor ultrasonico
  15.  
  16.  
  17. //Definicoes de IP, mascara de rede e gateway
  18. byte mac[] = {
  19. 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  20. IPAddress ip(192,168,1,88); //Define o endereco IP
  21. IPAddress gateway(192,168,1,1); //Define o gateway
  22. IPAddress subnet(255, 255, 255, 0); //Define a máscara de rede
  23.  
  24. //Inicializa o servidor web na porta 80
  25. EthernetServer server(80);
  26.  
  27. void setup()
  28. {
  29. //Inicializa a interface de rede
  30. Ethernet.begin(mac, ip, gateway, subnet);
  31. server.begin();
  32. pinMode(PINO_TRIGGER,OUTPUT);//EU QUE FIZ ISSO (LUCAS AQUI)
  33. }
  34.  
  35. void loop() {
  36. float cmMsec;
  37.  
  38.  
  39. //Aguarda conexao do browser
  40. EthernetClient client = server.available();
  41. if (client) {
  42. Serial.println("new client");
  43. // an http request ends with a blank line
  44. boolean currentLineIsBlank = true;
  45. while (client.connected()) {
  46. if (client.available()) {
  47. digitalWrite(PINO_TRIGGER, HIGH);//EU QUE FIZ ISSO (LUCAS AQUI)
  48. delay(600);//EU QUE FIZ ISSO (LUCAS AQUI)
  49. char c = client.read();
  50. Serial.write(c);
  51. // if you've gotten to the end of the line (received a newline
  52. // character) and the line is blank, the http request has ended,
  53. // so you can send a reply
  54. if (c == 'n' && currentLineIsBlank) {
  55. // send a standard http response header
  56. client.println("HTTP/1.1 200 OK");
  57. client.println("Content-Type: text/html");
  58. client.println("Connection: close");
  59. client.println("Refresh: 2"); //Recarrega a pagina a cada 2seg
  60. client.println();
  61. client.println("<!DOCTYPE HTML>");
  62. client.println("<html>");
  63. //Configura o texto e imprime o titulo no browser
  64. client.print("<font color=#FF0000><b><u>");
  65. client.print("Envio de informacoes pela rede utilizando Arduino");
  66. client.print("</u></b></font>");
  67. client.println("<br />");
  68. client.println("<br />");
  69. //Mostra o estado da porta digital 3
  70. int porta_digital = digitalRead(3);
  71. client.print("Porta Digital 3 : ");
  72. client.print("<b>");
  73. client.print(porta_digital);
  74. client.println("</b>");
  75. client.print(" (0 = Desligada, 1 = Ligada)");
  76. client.println("<br />");
  77. //Mostra as informacoes lidas pelo sensor ultrasonico
  78. client.print("LIGA LED : ");
  79. client.print("<b>");
  80. client.print(cmMsec);
  81. client.print(" cm");
  82. client.println("</b></html>");
  83. break;
  84. }
  85. if (c == 'n') {
  86. // you're starting a new line
  87. currentLineIsBlank = true;
  88. }
  89. else if (c != 'r') {
  90. // you've gotten a character on the current line
  91. currentLineIsBlank = false;
  92. }
  93. }
  94. }
  95. // give the web browser time to receive the data
  96. delay(1);
  97. // close the connection:
  98. client.stop();
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement