Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********** Proyecto **********
- * Universidad Santiago de Cali
- *
- * Laboratorio 11: Envio de mensajes desde Arduino a una matriz LED 8X8,
- * utilizando un formulario web para enviar el mensaje.
- ¨*
- * Autor: Daniel López Huertas
- * Descripcion: Enviar desde un formulario web un mensaje a una matriz
- * LED 8x8 (desplazándose de izquierda a derecha) a través de IC MAX7219.
- * Version: 1
- Circuit:
- * Ethernet shield attached to pins 10, 11, 12, 13
- * Analog inputs attached to pins A0 through A5 (optional)
- */
- //librerias necesarias para el buen funcionamiento
- #include <SPI.h>
- #include <Ethernet.h>
- #include "LedControl.h"
- #define BUFSIZ 100 //Buffer size for getting data
- //definición de las direcciones MAC e IP.
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- IPAddress ip(192, 168, 0, 107);
- EthernetServer server(80);
- int data_in = 9; //se inicializa la variable data_in en el PIN 9
- int clock = 7; //se inicializa la variable data_in en el PIN 7
- int cs = 8; //se inicializa la variable data_in en el PIN 8
- LedControl lc = LedControl(data_in, clock, cs, 1); //se instacia un objeto de ledControl para utilizar los PINES
- /* we always wait a bit between updates of the display */
- unsigned long delaytime = 100;
- void setup()
- {
- Ethernet.begin(mac, ip);
- server.begin();
- //pinMode(LED, OUTPUT);
- Serial.begin(9600);
- /*
- The MAX72XX is in power-saving mode on startup,
- we have to do a wakeup call
- */
- lc.shutdown(0, false);
- /* Set the brightness to a medium values */
- lc.setIntensity(0, 8);
- /* and clear the display */
- lc.clearDisplay(0);
- }
- void loop()
- {
- char clientline[BUFSIZ]; //string that will contain command data
- int index = 0; //clientline index
- int pos = 0;
- EthernetClient client = server.available();
- if (client) {
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- if (index < BUFSIZ) //Only add data if the buffer isn't full.
- clientline[index++] = c;
- if (c == '\n' && currentLineIsBlank)
- {
- if ((pos = strstr(clientline, "/?texto=") != 0)) {
- // Extraer el mensaje despues del igual
- String cadena = String(clientline);
- String mensaje = cadena.substring(pos + 11, cadena.indexOf(" ", pos + 11));
- Serial.print(mensaje);
- // el método que muestra el mensaje en la pantalla
- writeArduinoOnMatrix(mensaje);
- }
- // send a standard http response header
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close"); // the connection will be closed after completion of the response
- // client.println("Refresh: 5"); // refresh the page automatically every 5 sec
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<head><title>MATRIZ LED</title></head>");
- client.println("<body>");
- client.println("<h1>MATRIZ LED<h1>");
- client.println("<form method='get'>");
- client.println("<label>texto de la Matriz:</label><input type='text' name='texto'/>");
- client.println("<input type='button' name='Matriz' value='Ingresar' onclick='submit();'/></form>");
- client.println("</body></html>");
- //Serial.println(clientline);
- break;
- }
- if (c == '\n') {
- currentLineIsBlank = true;
- }
- else if (c != '\r') {
- currentLineIsBlank = false;
- }
- }
- }
- delay(1);
- client.stop();
- }
- }
- //Arreglo con las letras en mayuscula, minusculas y números.
- byte letras[63][5] = { {B11111110, B00010001, B00010001, B00010001, B11111110}, //A
- {0xFF, 0x89, 0x89, 0x89, 0x76},//B
- {B01111110, B10000001, B10000001, B10000001, B01000110}, //C
- {0xff, 0x81, 0x81, 0x81, 0x7e},//D
- {0x7e, 0x89, 0x89, 0x89, 0x89},//E
- {0xff, 0x09, 0x09, 0x09, 0x01},//F
- {0x7e, 0x89, 0x89, 0x89, 0xf2},//G
- {0xFF, 0x18, 0x18, 0x18, 0xff}, //H
- {B00000000, B10000100, B11111101, B10000000, B00000000}, //I
- {0x71, 0x81, 0x7f, 0x01, 0x01},//J
- {0xff, 0x10, 0x2c, 0x42, 0x81},//K
- {0x7f, 0xc0, 0x80, 0x80, 0x80}, //L
- {0xff, 0x06, 0x0c, 0x06, 0xff},//M
- {B11111111, B00000100, B00001000, B00010000, B11111111}, //N
- {B01111110, B10000001, B10000001, B10000001, B01111110}, //O
- {0xff, 0x09, 0x09, 0x09, 0x06},//P
- {0xbe, 0x41, 0xA1, 0x81, 0x7e}, //Q
- {B11111111, B00010001, B00110001, B01010001, B10001110}, //R
- {0x86, 0x89, 0x89, 0x89, 0x71},//S
- {0x01, 0x01, 0xff, 0x01, 0x01},//T
- {B01111111, B11000000, B11000000, B11000000, B01111111}, //U
- {0x3f, 0x40, 0x80, 0x40, 0x3f},//V
- {0x7f, 0x80, 0x70, 0x80, 0x7f},//W
- {0xe3, 0x14, 0x08, 0x14, 0xe3},//X
- {0x03, 0x04, 0xf8, 0x04, 0x03},//Y
- {0xe1, 0x91, 0x89, 0x85, 0x83},//Z
- {0xd68, 0xd94, 0xd94, 0xd78, 0xd80},//a
- {0xdfc, 0xd60, 0xd90, 0xd90, 0xd60},//b
- {0xd78, 0xd84, 0xd84, 0xd84, 0x48},//c
- {0xd60, 0xd90, 0xd90, 0xd60, 0xdfc},//d
- {0x78, 0x94, 0x94, 0x94, 0x58},//e
- {B11111100, B00100100, B00100100, B00000100, B00000100},//f
- {B00001000, B10010100, B10010100, B10110100, B01001000},//g
- {B11111100, B00100000, B00010000, B00010000, B11100000},//h
- {B00000000, B00000000, B11110100, B00000000, B00000000},//i
- {B10000000, B10000000, B01110100, B00000000, B00000000},//j
- {B11111100, B00100000, B01010000, B10001000, B00000000},//k
- {B00000000, B00000000, B11111100, B10000000, B00000000},//l
- {B11111100, B00001000, B11110000, B00001000, B11110000},//m
- {0x78, 0x94, 0x94, 0x94, 0x58},//n
- {0x78, 0x94, 0x94, 0x94, 0x58},//o
- {0x78, 0x94, 0x94, 0x94, 0x58},//p
- {0x78, 0x94, 0x94, 0x94, 0x58},//q
- {0x78, 0x94, 0x94, 0x94, 0x58},//r
- {0x78, 0x94, 0x94, 0x94, 0x58},//s
- {0x78, 0x94, 0x94, 0x94, 0x58},//t
- {0x78, 0x94, 0x94, 0x94, 0x58},//u
- {0x78, 0x94, 0x94, 0x94, 0x58},//v
- {0x78, 0x94, 0x94, 0x94, 0x58},//w
- {0x78, 0x94, 0x94, 0x94, 0x58},//x
- {0x78, 0x94, 0x94, 0x94, 0x58},//y
- {0x78, 0x94, 0x94, 0x94, 0x58},//z
- {B01111110, B11100001, B10011001, B10000111, B01111110}, //O
- {0x00, 0x82, 0xff, 0x80, 0x00}, //1
- {0xc2, 0xa1, 0x91, 0x89, 0x86},//2
- {0x81, 0x81, 0x85, 0x8b, 0x71}, //3
- {0x18, 0x14, 0x12, 0xff, 0x00}, //4
- {0x8f, 0x89, 0x89, 0x89, 0x71},//5
- {0x7c, 0x8a, 0x89, 0x89, 0x70},//6
- {0x01, 0xf1, 0x09, 0x05, 0x03}, //7
- {0x76, 0x89, 0x89, 0x89, 0x76},//8
- {0x06, 0x89, 0x89, 0x89, 0x7e }, //9
- {0x80, 0x00, 0x80, 0x00, 0x80 } // tres puntos
- };
- /*
- This method will display the characters for the
- word "Arduino" one after the other on the matrix.
- (you need at least 5x7 leds to see the whole chars)
- */
- void writeArduinoOnMatrix(String mensajea) {
- /* here is the data for the characters */
- for (int j = 0; j < mensajea.length(); j++) {
- int pos = 0;
- char ch = mensajea.charAt(j);
- if (ch >= 'A' && ch <= 'Z') pos = ch - 'A';
- else if (ch >= 'a' && ch <= 'z') pos = ch - 'a' + 26;
- else if (ch >= '0' && ch <= '9') pos = ch - '0' + 52;
- else pos = 62;
- palabras(letras[pos]);
- }
- }
- void palabras(byte listd[]) {
- for (int j = 7; j > -4; j--) {
- for (int i = 4; i > -1; i--) {
- lc.setRow(0, j + i, listd[i]);
- }
- delay(delaytime);
- for (int o = 0; o < 8 ; o++) {
- lc.setRow(0, o, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment