Advertisement
CrhisDLM

Lab 10 Matriz

Jul 7th, 2025
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.10 KB | None | 0 0
  1. /*
  2.   Web Server
  3.  
  4.   A simple web server that shows the value of the analog input pins.
  5.   using an Arduino Wiznet Ethernet shield.
  6.  
  7.   Circuit:
  8.    Ethernet shield attached to pins 10, 11, 12, 13
  9.    Analog inputs attached to pins A0 through A5 (optional)
  10.  
  11.   created 18 Dec 2009
  12.   by David A. Mellis
  13.   modified 9 Apr 2012
  14.   by Tom Igoe
  15.   modified 02 Sept 2015
  16.   by Arturo Guadalupi
  17.  
  18. */
  19.  
  20. #include <SPI.h>
  21. #include <Ethernet.h>
  22. #include "LedControl.h"
  23. // Enter a MAC address and IP address for your controller below.
  24. // The IP address will be dependent on your local network:
  25. byte mac[] = {
  26.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  27. };
  28. IPAddress ip(192, 168, 1, 177);
  29.  
  30. // Initialize the Ethernet server library
  31. // with the IP address and port you want to use
  32. // (port 80 is default for HTTP):
  33. EthernetServer server(80);
  34. char abcMAY[36] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
  35. char abcMIN[36] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
  36. byte letras[36][5] = { {B11111110, B00010001, B00010001, B00010001, B11111110}, //A
  37.   {0xFF, 0x89, 0x89, 0x89, 0x76},//B
  38.   {B01111110, B10000001, B10000001, B10000001, B01000110}, //C
  39.   {0xff, 0x81, 0x81, 0x81, 0x7e},//D
  40.   {0x7e, 0x89, 0x89, 0x89, 0x89},//E
  41.   {0xff, 0x09, 0x09, 0x09, 0x01},//F
  42.   {0x7e, 0x89, 0x89, 0x89, 0xf2},//G
  43.   {0xFF, 0x18, 0x18, 0x18, 0xff}, //H
  44.   {B00000000, B10000100, B11111101, B10000000, B00000000}, //I
  45.   {0x71, 0x81, 0x7f, 0x01, 0x01},//J
  46.   {0xff, 0x10, 0x2c, 0x42, 0x81},//K
  47.   {0x7f, 0xc0, 0x80, 0x80, 0x80}, //L
  48.   {0xff, 0x06, 0x0c, 0x06, 0xff},//M
  49.   {B11111111, B00000100, B00001000, B00010000, B11111111}, //N
  50.   {B01111110, B10000001, B10000001, B10000001, B01111110}, //O
  51.   {0xff, 0x09, 0x09, 0x09, 0x06},//P
  52.   {0xbe, 0x41, 0xA1, 0x81, 0x7e}, //Q
  53.   {B11111111, B00010001, B00110001, B01010001, B10001110}, //R
  54.   {0x86, 0x89, 0x89, 0x89, 0x71},//S
  55.   {0x01, 0x01, 0xff, 0x01, 0x01},//T
  56.   {B01111111, B11000000, B11000000, B11000000, B01111111}, //U
  57.   {0x3f, 0x40, 0x80, 0x40, 0x3f},//V
  58.   {0x7f, 0x80, 0x70, 0x80, 0x7f},//W
  59.   {0xe3, 0x14, 0x08, 0x14, 0xe3},//X
  60.   {0x03, 0x04, 0xf8, 0x04, 0x03},//Y
  61.   {0xe1, 0x91, 0x89, 0x85, 0x83 },//Z
  62.  
  63.   {0x00, 0x82, 0xff, 0x80, 0x00}, //1
  64.   {0xc2, 0xa1, 0x91, 0x89, 0x86},//2
  65.   {0x81, 0x81, 0x85, 0x8b, 0x71}, //3
  66.   {0x18, 0x14, 0x12, 0xff, 0x00}, //4
  67.   {0x8f, 0x89, 0x89, 0x89, 0x71},//5
  68.   {0x7c, 0x8a, 0x89, 0x89, 0x70},//6
  69.   {0x01, 0xf1, 0x09, 0x05, 0x03}, //7
  70.   {0x76, 0x89, 0x89, 0x89, 0x76},//8
  71.   {0x06, 0x89, 0x89, 0x89, 0x7e },//9
  72.   {B01111110, B11100001, B10011001, B10000111, B01111110}, //O
  73. };
  74. String texto = "Esperando Texto";
  75. /*
  76.   Now we need a LedControl to work with.
  77.  ***** These pin numbers will probably not work with your hardware *****
  78.   pin 12 is connected to the DataIn
  79.   pin 11 is connected to the CLK
  80.   pin 10 is connected to LOAD
  81.   We have only a single MAX72XX.
  82. */
  83. LedControl lc = LedControl(9, 8, 7, 1);
  84.  
  85. /* we always wait a bit between updates of the display */
  86. unsigned long delaytime = 85;
  87. void setup() {
  88.   // Open serial communications and wait for port to open:
  89.   Serial.begin(9600);
  90.   while (!Serial) {
  91.     ; // wait for serial port to connect. Needed for native USB port only
  92.   }
  93.  
  94.  
  95.   // start the Ethernet connection and the server:
  96.   Ethernet.begin(mac, ip);
  97.   server.begin();
  98.  
  99.   Serial.print("server is at ");
  100.   Serial.println(Ethernet.localIP());
  101.   lc.shutdown(0, false);
  102.   /* Set the brightness to a medium values */
  103.   lc.setIntensity(0, 8);
  104.   /* and clear the display */
  105.   lc.clearDisplay(0);
  106. }
  107.  
  108.  
  109. void loop() {
  110.   // listen for incoming clients
  111.   EthernetClient client = server.available();
  112.   if (client) {
  113.     Serial.println("new client");
  114.     // an http request ends with a blank line
  115.     boolean currentLineIsBlank = true;
  116.     while (client.connected()) {
  117.       if (client.available()) {
  118.         char c = client.read();
  119.         Serial.write(c);
  120.         // if you've gotten to the end of the line (received a newline
  121.         // character) and the line is blank, the http request has ended,
  122.         // so you can send a reply
  123.         if (c == '\n' && currentLineIsBlank) {
  124.           // send a standard http response header
  125.           client.println("HTTP/1.1 200 OK");
  126.           client.println("Content-Type: text/html");
  127.           client.println("Connection: close");  // the connection will be closed after completion of the response
  128.           //client.println("Refresh: 5");  // refresh the page automatically every 5 sec
  129.           client.println();
  130.           client.println("<!DOCTYPE HTML>");
  131.           client.println("<html><body style=\"background: #14682E linear-gradient(90deg,rgba(20, 104, 46, 1) 0%, rgba(237, 221, 83, 1) 100%);\"><script></script>");
  132.           // output the value of each analog input pin
  133.           client.print("<form>");
  134.           client.print("<input style=\"font-size: 24px;\" name=\"msj\">");
  135.           client.print("<input style=\"font-size: 24px;\" type=\"submit\">");
  136.           client.print("</form>");
  137.           client.print("</body>");
  138.           client.println("</html>");
  139.           break;
  140.         }
  141.         if (c == 'G') {
  142.           Serial.println("Peticion Detectada");
  143.           String peticion = getString(client);
  144.           if (peticion.indexOf("msj") != -1) {
  145.             int posi = peticion.indexOf("=");
  146.             int posf = peticion.indexOf("HTTP");
  147.             if (posf == -1)
  148.               texto = peticion.substring(posi + 1);
  149.             else
  150.               texto = peticion.substring(posi + 1, posf);
  151.             Serial.println(texto);
  152.  
  153.             client.flush(); // limpia el resto del contenido de la peticion
  154.           }
  155.  
  156.           Serial.println(texto);
  157.         }
  158.         if (c == '\n') {
  159.           // you're starting a new line
  160.           currentLineIsBlank = true;
  161.         } else if (c != '\r') {
  162.           // you've gotten a character on the current line
  163.           currentLineIsBlank = false;
  164.         }
  165.       }
  166.     }
  167.     // give the web browser time to receive the data
  168.     delay(1);
  169.     // close the connection:
  170.     client.stop();
  171.     Serial.println("client disconnected");
  172.   }
  173.   writeArduinoOnMatrix(texto);
  174.  
  175. }
  176. String getString(EthernetClient client) {
  177.   char s = client.read();
  178.   String p = "";
  179.   unsigned long timeout = millis();
  180.   while (s != '\n' && ((millis() - timeout) < 10000)) {
  181.     p += s;
  182.     s = client.read();
  183.   }
  184.   return p;
  185. }
  186. void writeArduinoOnMatrix(String mensajea) {
  187.   /* here is the data for the characters */
  188.  
  189.  
  190.   for (int j = 0; j < mensajea.length(); j++) {
  191.     for (int k = 0; k < 36; k++) {
  192.       if (mensajea.charAt(j) == abcMAY[k] || mensajea.charAt(j) == abcMIN[k]) {
  193.         palabras(letras[k]);
  194.       }
  195.     }
  196.   }
  197.  
  198. }
  199. void palabras(byte listd[]) {
  200.   for (int j = 7; j > -4; j--) {
  201.  
  202.     for (int i = 4; i > -1; i--) {
  203.       lc.setRow(0, j + i, listd[i]);
  204.     }
  205.     delay(delaytime);
  206.     for (int o = 0; o < 8 ; o++) {
  207.       lc.setRow(0, o, 0);
  208.     }
  209.   }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement