dalohuer2004

Laboratorio 11 Arduino

Jun 1st, 2015
1,620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.42 KB | None | 0 0
  1. /********** Proyecto **********
  2.  * Universidad Santiago de Cali
  3.  *
  4.  * Laboratorio 11: Envio de mensajes desde Arduino a una matriz LED 8X8,
  5.  * utilizando un formulario web para enviar el mensaje.
  6. ¨*
  7.  * Autor: Daniel López Huertas
  8.  * Descripcion: Enviar desde un formulario web un mensaje a una matriz
  9.  * LED 8x8 (desplazándose de izquierda a derecha) a través de IC MAX7219.
  10.  * Version: 1
  11.  
  12.  Circuit:
  13.  * Ethernet shield attached to pins 10, 11, 12, 13
  14.  * Analog inputs attached to pins A0 through A5 (optional)
  15. */
  16.  
  17. //librerias necesarias para el buen funcionamiento
  18. #include <SPI.h>
  19. #include <Ethernet.h>
  20. #include "LedControl.h"
  21. #define BUFSIZ 100  //Buffer size for getting data
  22.  
  23. //definición de las direcciones MAC e IP.
  24. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  25. IPAddress ip(192, 168, 0, 107);
  26. EthernetServer server(80);
  27.  
  28.  
  29. int data_in = 9;    //se inicializa la variable data_in en el PIN 9
  30. int clock = 7;       //se inicializa la variable data_in en el PIN 7
  31. int cs = 8;         //se inicializa la variable data_in en el PIN 8
  32. LedControl lc = LedControl(data_in, clock, cs, 1);    //se instacia un objeto de ledControl para utilizar los PINES
  33.  
  34. /* we always wait a bit between updates of the display */
  35. unsigned long delaytime = 100;
  36.  
  37. void setup()
  38. {
  39.   Ethernet.begin(mac, ip);
  40.   server.begin();
  41.   //pinMode(LED, OUTPUT);
  42.   Serial.begin(9600);
  43.  
  44.   /*
  45.    The MAX72XX is in power-saving mode on startup,
  46.    we have to do a wakeup call
  47.    */
  48.   lc.shutdown(0, false);
  49.   /* Set the brightness to a medium values */
  50.   lc.setIntensity(0, 8);
  51.   /* and clear the display */
  52.   lc.clearDisplay(0);
  53. }
  54.  
  55. void loop()
  56. {
  57.   char clientline[BUFSIZ];  //string that will contain command data
  58.   int index = 0;  //clientline index
  59.   int pos = 0;
  60.   EthernetClient client = server.available();
  61.   if (client) {
  62.     boolean currentLineIsBlank = true;
  63.     while (client.connected()) {
  64.       if (client.available()) {
  65.         char c = client.read();
  66.         if (index < BUFSIZ) //Only add data if the buffer isn't full.
  67.           clientline[index++] = c;
  68.         if (c == '\n' && currentLineIsBlank)
  69.         {
  70.           if ((pos = strstr(clientline, "/?texto=") != 0)) {
  71.             // Extraer el mensaje despues del igual
  72.             String cadena = String(clientline);
  73.             String mensaje = cadena.substring(pos + 11, cadena.indexOf(" ", pos + 11));
  74.             Serial.print(mensaje);
  75.             // el método que muestra el mensaje en la pantalla
  76.            
  77.             writeArduinoOnMatrix(mensaje);
  78.            
  79.           }
  80.           // send a standard http response header
  81.           client.println("HTTP/1.1 200 OK");
  82.           client.println("Content-Type: text/html");
  83.           client.println("Connection: close");  // the connection will be closed after completion of the response
  84.           // client.println("Refresh: 5");  // refresh the page automatically every 5 sec
  85.           client.println();
  86.           client.println("<!DOCTYPE HTML>");
  87.           client.println("<html>");
  88.           client.println("<head><title>MATRIZ LED</title></head>");
  89.           client.println("<body>");
  90.           client.println("<h1>MATRIZ LED<h1>");
  91.           client.println("<form method='get'>");
  92.           client.println("<label>texto de la Matriz:</label><input type='text' name='texto'/>");
  93.           client.println("<input type='button' name='Matriz' value='Ingresar' onclick='submit();'/></form>");
  94.           client.println("</body></html>");
  95.           //Serial.println(clientline);
  96.           break;
  97.         }
  98.         if (c == '\n') {
  99.           currentLineIsBlank = true;
  100.         }
  101.         else if (c != '\r') {
  102.           currentLineIsBlank = false;
  103.         }
  104.       }
  105.     }
  106.     delay(1);
  107.     client.stop();
  108.   }
  109. }
  110.  
  111. //Arreglo con las letras en mayuscula, minusculas y números.
  112.  
  113. byte letras[63][5] = { {B11111110, B00010001, B00010001, B00010001, B11111110}, //A
  114.   {0xFF, 0x89, 0x89, 0x89, 0x76},//B
  115.   {B01111110, B10000001, B10000001, B10000001, B01000110}, //C
  116.   {0xff, 0x81, 0x81, 0x81, 0x7e},//D
  117.   {0x7e, 0x89, 0x89, 0x89, 0x89},//E
  118.   {0xff, 0x09, 0x09, 0x09, 0x01},//F
  119.   {0x7e, 0x89, 0x89, 0x89, 0xf2},//G
  120.   {0xFF, 0x18, 0x18, 0x18, 0xff}, //H
  121.   {B00000000, B10000100, B11111101, B10000000, B00000000}, //I
  122.   {0x71, 0x81, 0x7f, 0x01, 0x01},//J
  123.   {0xff, 0x10, 0x2c, 0x42, 0x81},//K
  124.   {0x7f, 0xc0, 0x80, 0x80, 0x80}, //L
  125.   {0xff, 0x06, 0x0c, 0x06, 0xff},//M
  126.   {B11111111, B00000100, B00001000, B00010000, B11111111}, //N
  127.   {B01111110, B10000001, B10000001, B10000001, B01111110}, //O
  128.   {0xff, 0x09, 0x09, 0x09, 0x06},//P
  129.   {0xbe, 0x41, 0xA1, 0x81, 0x7e}, //Q
  130.   {B11111111, B00010001, B00110001, B01010001, B10001110}, //R
  131.   {0x86, 0x89, 0x89, 0x89, 0x71},//S
  132.   {0x01, 0x01, 0xff, 0x01, 0x01},//T
  133.   {B01111111, B11000000, B11000000, B11000000, B01111111}, //U
  134.   {0x3f, 0x40, 0x80, 0x40, 0x3f},//V
  135.   {0x7f, 0x80, 0x70, 0x80, 0x7f},//W
  136.   {0xe3, 0x14, 0x08, 0x14, 0xe3},//X
  137.   {0x03, 0x04, 0xf8, 0x04, 0x03},//Y
  138.   {0xe1, 0x91, 0x89, 0x85, 0x83},//Z
  139.   {0xd68, 0xd94, 0xd94, 0xd78, 0xd80},//a
  140.   {0xdfc, 0xd60, 0xd90, 0xd90, 0xd60},//b
  141.   {0xd78, 0xd84, 0xd84, 0xd84, 0x48},//c
  142.   {0xd60, 0xd90, 0xd90, 0xd60, 0xdfc},//d
  143.   {0x78, 0x94, 0x94, 0x94, 0x58},//e
  144.   {B11111100, B00100100, B00100100, B00000100, B00000100},//f
  145.   {B00001000, B10010100, B10010100, B10110100, B01001000},//g
  146.   {B11111100, B00100000, B00010000, B00010000, B11100000},//h
  147.   {B00000000, B00000000, B11110100, B00000000, B00000000},//i
  148.   {B10000000, B10000000, B01110100, B00000000, B00000000},//j
  149.   {B11111100, B00100000, B01010000, B10001000, B00000000},//k
  150.   {B00000000, B00000000, B11111100, B10000000, B00000000},//l
  151.   {B11111100, B00001000, B11110000, B00001000, B11110000},//m
  152.   {0x78, 0x94, 0x94, 0x94, 0x58},//n
  153.   {0x78, 0x94, 0x94, 0x94, 0x58},//o
  154.   {0x78, 0x94, 0x94, 0x94, 0x58},//p
  155.   {0x78, 0x94, 0x94, 0x94, 0x58},//q
  156.   {0x78, 0x94, 0x94, 0x94, 0x58},//r
  157.   {0x78, 0x94, 0x94, 0x94, 0x58},//s
  158.   {0x78, 0x94, 0x94, 0x94, 0x58},//t
  159.   {0x78, 0x94, 0x94, 0x94, 0x58},//u
  160.   {0x78, 0x94, 0x94, 0x94, 0x58},//v
  161.   {0x78, 0x94, 0x94, 0x94, 0x58},//w
  162.   {0x78, 0x94, 0x94, 0x94, 0x58},//x
  163.   {0x78, 0x94, 0x94, 0x94, 0x58},//y
  164.   {0x78, 0x94, 0x94, 0x94, 0x58},//z
  165.   {B01111110, B11100001, B10011001, B10000111, B01111110}, //O
  166.   {0x00, 0x82, 0xff, 0x80, 0x00}, //1
  167.   {0xc2, 0xa1, 0x91, 0x89, 0x86},//2
  168.   {0x81, 0x81, 0x85, 0x8b, 0x71}, //3
  169.   {0x18, 0x14, 0x12, 0xff, 0x00}, //4
  170.   {0x8f, 0x89, 0x89, 0x89, 0x71},//5
  171.   {0x7c, 0x8a, 0x89, 0x89, 0x70},//6
  172.   {0x01, 0xf1, 0x09, 0x05, 0x03}, //7
  173.   {0x76, 0x89, 0x89, 0x89, 0x76},//8
  174.   {0x06, 0x89, 0x89, 0x89, 0x7e }, //9
  175.   {0x80, 0x00, 0x80, 0x00, 0x80 } // tres puntos
  176. };
  177.  
  178. /*
  179.  This method will display the characters for the
  180.  word "Arduino" one after the other on the matrix.
  181.  (you need at least 5x7 leds to see the whole chars)
  182.  */
  183. void writeArduinoOnMatrix(String mensajea) {
  184.   /* here is the data for the characters */
  185.  
  186.   for (int j = 0; j < mensajea.length(); j++) {
  187.     int pos = 0;
  188.     char ch = mensajea.charAt(j);
  189.     if (ch >= 'A' && ch <= 'Z') pos = ch - 'A';
  190.     else if (ch >= 'a' && ch <= 'z') pos = ch - 'a' + 26;
  191.     else if (ch >= '0' && ch <= '9') pos = ch - '0' + 52;
  192.     else pos = 62;
  193.     palabras(letras[pos]);
  194.   }
  195. }
  196.  
  197. void palabras(byte listd[]) {
  198.   for (int j = 7; j > -4; j--) {
  199.  
  200.     for (int i = 4; i > -1; i--) {
  201.       lc.setRow(0, j + i, listd[i]);
  202.     }
  203.     delay(delaytime);
  204.     for (int o = 0; o < 8 ; o++) {
  205.       lc.setRow(0, o, 0);
  206.     }
  207.   }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment