Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Web Server
- A simple web server that shows the value of the analog input pins.
- using an Arduino Wiznet Ethernet shield.
- Circuit:
- Ethernet shield attached to pins 10, 11, 12, 13
- Analog inputs attached to pins A0 through A5 (optional)
- created 18 Dec 2009
- by David A. Mellis
- modified 9 Apr 2012
- by Tom Igoe
- modified 02 Sept 2015
- by Arturo Guadalupi
- */
- #include <SPI.h>
- #include <Ethernet.h>
- #include "LedControl.h"
- // Enter a MAC address and IP address for your controller below.
- // The IP address will be dependent on your local network:
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- IPAddress ip(192, 168, 1, 177);
- // Initialize the Ethernet server library
- // with the IP address and port you want to use
- // (port 80 is default for HTTP):
- EthernetServer server(80);
- 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'};
- 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'};
- byte letras[36][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
- {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
- {B01111110, B11100001, B10011001, B10000111, B01111110}, //O
- };
- String texto = "Esperando Texto";
- /*
- Now we need a LedControl to work with.
- ***** These pin numbers will probably not work with your hardware *****
- pin 12 is connected to the DataIn
- pin 11 is connected to the CLK
- pin 10 is connected to LOAD
- We have only a single MAX72XX.
- */
- LedControl lc = LedControl(9, 8, 7, 1);
- /* we always wait a bit between updates of the display */
- unsigned long delaytime = 85;
- void setup() {
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB port only
- }
- // start the Ethernet connection and the server:
- Ethernet.begin(mac, ip);
- server.begin();
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- lc.shutdown(0, false);
- /* Set the brightness to a medium values */
- lc.setIntensity(0, 8);
- /* and clear the display */
- lc.clearDisplay(0);
- }
- void loop() {
- // listen for incoming clients
- EthernetClient client = server.available();
- if (client) {
- Serial.println("new client");
- // an http request ends with a blank line
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- Serial.write(c);
- // if you've gotten to the end of the line (received a newline
- // character) and the line is blank, the http request has ended,
- // so you can send a reply
- if (c == '\n' && currentLineIsBlank) {
- // 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><body style=\"background: #14682E linear-gradient(90deg,rgba(20, 104, 46, 1) 0%, rgba(237, 221, 83, 1) 100%);\"><script></script>");
- // output the value of each analog input pin
- client.print("<form>");
- client.print("<input style=\"font-size: 24px;\" name=\"msj\">");
- client.print("<input style=\"font-size: 24px;\" type=\"submit\">");
- client.print("</form>");
- client.print("</body>");
- client.println("</html>");
- break;
- }
- if (c == 'G') {
- Serial.println("Peticion Detectada");
- String peticion = getString(client);
- if (peticion.indexOf("msj") != -1) {
- int posi = peticion.indexOf("=");
- int posf = peticion.indexOf("HTTP");
- if (posf == -1)
- texto = peticion.substring(posi + 1);
- else
- texto = peticion.substring(posi + 1, posf);
- Serial.println(texto);
- client.flush(); // limpia el resto del contenido de la peticion
- }
- Serial.println(texto);
- }
- if (c == '\n') {
- // you're starting a new line
- currentLineIsBlank = true;
- } else if (c != '\r') {
- // you've gotten a character on the current line
- currentLineIsBlank = false;
- }
- }
- }
- // give the web browser time to receive the data
- delay(1);
- // close the connection:
- client.stop();
- Serial.println("client disconnected");
- }
- writeArduinoOnMatrix(texto);
- }
- String getString(EthernetClient client) {
- char s = client.read();
- String p = "";
- unsigned long timeout = millis();
- while (s != '\n' && ((millis() - timeout) < 10000)) {
- p += s;
- s = client.read();
- }
- return p;
- }
- void writeArduinoOnMatrix(String mensajea) {
- /* here is the data for the characters */
- for (int j = 0; j < mensajea.length(); j++) {
- for (int k = 0; k < 36; k++) {
- if (mensajea.charAt(j) == abcMAY[k] || mensajea.charAt(j) == abcMIN[k]) {
- palabras(letras[k]);
- }
- }
- }
- }
- 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
Advertisement