#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);
LedControl lc=LedControl(7,6,5,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=100;
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
String readString;
void setup()
{
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
} // open up serial port connection to PC
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
/*
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 writeArduinoOnMatrix() {
/* here is the data for the characters */
byte a[8]={B00000000,B00100000,B01100000,B11111111,B11111111,B01100000,B00100000,B00000000};
/* now display them one by one with a small delay /
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
lc.setRow(0,9,a[8]);
}
void writeArduinoOnMatrix5() {
/ here is the data for the characters */
byte a[8]={B11111111,B11000011,B10100101,B10011001,B10011001,B10100101,B11000011,B11111111};
/* now display them one by one with a small delay /
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
lc.setRow(0,9,a[8]);
}
void writeArduinoOnMatrix2() {
/ here is the data for the characters */
byte a[8]={B00000000,B00000100,B00000110,B11111111,B11111111,B00000110,B00000100,B00000000};
/* now display them one by one with a small delay /
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
lc.setRow(0,9,a[8]);
}
void writeArduinoOnMatrix3() {
/ here is the data for the characters */
byte a[8]={B00011000,B00111100,B01111110,B00011000,B00011000,B00011000,B00011000,B00011000};
/* now display them one by one with a small delay /
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
lc.setRow(0,9,a[8]);
}
void writeArduinoOnMatrix4() {
/ here is the data for the characters */
byte a[8]={B00011000,B00011000,B00011000,B00011000,B00011000,B01111110,B00111100,B00011000};
/* now display them one by one with a small delay */
lc.setRow(0,0,a[0]);
lc.setRow(0,1,a[1]);
lc.setRow(0,2,a[2]);
lc.setRow(0,3,a[3]);
lc.setRow(0,4,a[4]);
lc.setRow(0,5,a[5]);
lc.setRow(0,6,a[6]);
lc.setRow(0,7,a[7]);
lc.setRow(0,9,a[8]);
}
void loop() {
// Create a client connection
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
String buffer = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c);
buffer+=c;
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n' ) {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println("");
client.println("");
client.println("");
client.println("");
client.println("MATRICE DE LED");
client.println("");
client.println("");
client.println("
MATRICE DE LED
");
client.println("
");
client.println("
");
client.println("
Choose your form
");
client.println("
");
client.println("<a href="/?haut"">Fleche haut");
client.println("<a href="/?bas"">Fleche bas
");
client.println("
");
client.println("
");
client.println("<a href="/?gauche"">Fleche gauche");
client.println("<a href="/?droite"">Fleche droite
");
client.println("
");
client.println("
");
client.print("<FORM action="
http://192.168.1.177/\" >");
client.print("
<input type="text" name="text" id="ST" value=""/>" );
client.println("
");
client.println("
");
client.print("
<INPUT type="submit" value="Submit"> ");
client.println("
");
client.println("");
client.println("");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?haut") >0)
writeArduinoOnMatrix() ;
if (readString.indexOf("?bas") >0)
writeArduinoOnMatrix2() ;
if (readString.indexOf("?gauche") >0)
writeArduinoOnMatrix3() ;
if (readString.indexOf("?droite") >0)
writeArduinoOnMatrix4() ;
if (readString.indexOf("?text") >0)
writeArduinoOnMatrix5() ;
readString="";
}
}}}}