Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*----------------------
- // Laboratorio #12
- // Mensaje con desplazamiento de izquierda a derecha
- // en LCD 16x2 enviado desde un servidor Web
- // Version 1.0
- // Carlos Andrés Mantilla
- // Octubre/2014
- //*----------------------
- /*
- Libreria LCD
- * pin LCD RS al pin 7
- * pin LCD Enable al pin 6
- * pin LCD D4 al pin 5
- * pin LCD D5 al pin 4
- * pin LCD D6 al pin 3
- * pin LCD D7 al pin 2
- * pin LCD R/W a tierra
- * resistencia 10K
- * pines alimentacion a +5V y tierra
- */
- // Incluimos Librerias Ethernet modificadas para el modulo W5200 Ethernet Shield
- #include <DhcpV2_0.h>
- #include <DnsV2_0.h>
- #include <EthernetClientV2_0.h>
- #include <EthernetServerV2_0.h>
- #include <EthernetUdpV2_0.h>
- #include <EthernetV2_0.h>
- #include <utilV2_0.h>
- // Incluimos las librerías:
- #include <LiquidCrystal.h>
- #include <SPI.h>
- #define max_he 255
- // Inicializamos la librería con los pines que utilizaremos
- LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //
- // Mac del modulo Ethernet
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- //direccion ip configurada para funcionar con el servidor local.
- byte ip[] = {
- 192,168,0,22};
- // Inicializar la librería de servidor Ethernet
- // con la dirección IP y el puerto que desee utilizar
- // (puerto 80 es el predeterminado para HTTP):
- EthernetServer server(80);
- String Http = String(max_he);
- void setup() {
- // Inicializamos el LCD
- lcd.begin(16, 2);
- Http = "";
- // Iniciamos la conexión con el servidor y se imprime en la
- // consola para conocer el estado de la conexion
- Ethernet.begin(mac, ip);
- server.begin();
- Serial.begin(9600);
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- // imprimimos la direccion IP en la LCD
- lcd.print(Ethernet.localIP());
- }
- // Bucle de trabajo
- void loop() {
- // se habilita la comunicacion con el servidor y se espera
- // cualquier dato ingresado desde la pagina
- EthernetClient client = server.available();
- if (client) {
- Http = "";
- Serial.println("new client");
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- if (Http.length() < max_he){
- Http += c;
- }
- if (c == '\n' && currentLineIsBlank) {
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close");
- // la conexión se cierra después de la finalización de la respuesta
- client.println("Refresh: 30"); // Refescamos cada 30 segundos
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<form method=\"GET\">");
- client.println("<input type=\"text\" name=\"msg\" size=\"10\" />");
- client.println("<input type=\"submit\">");
- client.println("</form>");
- client.println("</html>");
- break;
- }
- if (c == '\n') {
- currentLineIsBlank = true;
- }
- else if (c != '\r') {
- currentLineIsBlank = false;
- }
- }
- }
- // Le damos tiempo al navegador para recibir los datos
- delay(1);
- // Cerramos la conexión:
- client.stop();
- Serial.println("client disonnected");
- // se rescata el string enviado y se imprime en la LCD
- int firstPos = Http.indexOf("?");
- if(firstPos > -1){
- int lastPos = Http.indexOf(" ", firstPos+5);
- String text = Http.substring(firstPos+5, lastPos);
- // Limpiar LCD
- lcd.clear();
- lcd.print(text);
- Serial.println(text);
- delay(200);
- // se hace el bucle de desplazamiento
- for (int i=0; i < 16; i++){
- lcd.scrollDisplayRight();
- delay(300);
- }
- // luego del desplazamiento se limpia la pantalla
- // en la espera de recibir otro dato
- lcd.clear();
- lcd.home();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement