document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //*----------------------
  2. // Laboratorio #12
  3. // Mensaje con desplazamiento de izquierda a derecha
  4. // en LCD 16x2 enviado desde un servidor Web
  5. // Version 1.0
  6. // Carlos Andrés Mantilla
  7. // Octubre/2014
  8. //*----------------------
  9.  
  10. /*
  11.   Libreria LCD
  12.  * pin LCD RS al pin 7
  13.  * pin LCD Enable al pin 6
  14.  * pin LCD D4 al pin 5
  15.  * pin LCD D5 al pin 4
  16.  * pin LCD D6 al pin 3
  17.  * pin LCD D7 al pin 2
  18.  * pin LCD R/W a tierra
  19.  * resistencia 10K
  20.  * pines alimentacion a +5V y tierra
  21.  */
  22.  
  23. // Incluimos Librerias Ethernet modificadas para el modulo W5200 Ethernet Shield
  24. #include <DhcpV2_0.h>
  25. #include <DnsV2_0.h>
  26. #include <EthernetClientV2_0.h>
  27. #include <EthernetServerV2_0.h>
  28. #include <EthernetUdpV2_0.h>
  29. #include <EthernetV2_0.h>
  30. #include <utilV2_0.h>
  31.  
  32. // Incluimos las librerías:
  33. #include <LiquidCrystal.h>
  34. #include <SPI.h>
  35. #define max_he 255
  36.  
  37. // Inicializamos la librería con los pines que utilizaremos
  38. LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //
  39. // Mac del modulo Ethernet
  40. byte mac[] = {
  41.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  42. //direccion ip configurada para funcionar con el servidor local.
  43. byte ip[]  = {
  44.   192,168,0,22};
  45.  
  46. // Inicializar la librería de servidor Ethernet
  47. // con la dirección IP y el puerto que desee utilizar
  48. // (puerto 80 es el predeterminado para HTTP):
  49. EthernetServer server(80);
  50. String Http = String(max_he);
  51.  
  52. void setup() {
  53.   // Inicializamos el LCD
  54.   lcd.begin(16, 2);
  55.   Http = "";
  56.  
  57.   // Iniciamos la conexión con el servidor y se imprime en la
  58.   // consola para conocer el estado de la conexion
  59.   Ethernet.begin(mac, ip);
  60.   server.begin();
  61.   Serial.begin(9600);
  62.   Serial.print("server is at ");
  63.   Serial.println(Ethernet.localIP());
  64.   // imprimimos la direccion IP en la LCD
  65.   lcd.print(Ethernet.localIP());
  66. }
  67.  
  68. // Bucle de trabajo
  69. void loop() {
  70.  
  71.   // se habilita la comunicacion con el servidor y se espera
  72.   // cualquier dato ingresado desde la pagina
  73.   EthernetClient client = server.available();
  74.   if (client) {
  75.     Http = "";
  76.     Serial.println("new client");
  77.     boolean currentLineIsBlank = true;
  78.     while (client.connected()) {
  79.       if (client.available()) {
  80.         char c = client.read();
  81.         if (Http.length() < max_he){
  82.           Http += c;
  83.         }
  84.         if (c == \'\\n\' && currentLineIsBlank) {
  85.           client.println("HTTP/1.1 200 OK");
  86.           client.println("Content-Type: text/html");
  87.           client.println("Connection: close");  
  88.           // la conexión se cierra después de la finalización de la respuesta
  89.           client.println("Refresh: 30");  // Refescamos cada 30 segundos
  90.           client.println();
  91.           client.println("<!DOCTYPE HTML>");
  92.           client.println("<html>");
  93.  
  94.           client.println("<form method=\\"GET\\">");
  95.           client.println("<input type=\\"text\\" name=\\"msg\\" size=\\"10\\" />");
  96.           client.println("<input type=\\"submit\\">");
  97.           client.println("</form>");
  98.           client.println("</html>");
  99.           break;
  100.         }
  101.         if (c == \'\\n\') {
  102.           currentLineIsBlank = true;
  103.         }
  104.         else if (c != \'\\r\') {
  105.  
  106.           currentLineIsBlank = false;
  107.         }
  108.       }
  109.     }
  110.     // Le damos tiempo al navegador para recibir los datos
  111.     delay(1);
  112.     // Cerramos la conexión:
  113.     client.stop();
  114.     Serial.println("client disonnected");
  115.  
  116.     // se rescata el string enviado y se imprime en la LCD
  117.     int firstPos = Http.indexOf("?");
  118.     if(firstPos > -1){
  119.       int lastPos = Http.indexOf(" ", firstPos+5);
  120.       String text = Http.substring(firstPos+5, lastPos);
  121.       // Limpiar LCD
  122.       lcd.clear();
  123.       lcd.print(text);
  124.       Serial.println(text);
  125.       delay(200);
  126.  
  127.       // se hace el bucle de desplazamiento
  128.       for (int i=0; i < 16; i++){
  129.         lcd.scrollDisplayRight();
  130.         delay(300);
  131.       }
  132.       // luego del desplazamiento se limpia la pantalla
  133.       // en la espera de recibir otro dato
  134.       lcd.clear();
  135.       lcd.home();
  136.  
  137.     }
  138.   }
  139. }
');