Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================DECLARANDO E CONFIGURANDO ETHERNET=============================================================//
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- byte ip[] = { 192, 168, 0, 5 };
- EthernetServer server(80);
- String readString;
- //===============================================================================DECLARANDO AS VARIAVEIS GLOBAIS==============================================================//
- boolean Led;
- //================================================================================ROTINA DE SETUP CONFIGURAÇÕES===============================================================//
- void setup(){
- pinMode(7, OUTPUT);
- // pinMode(26, OUTPUT);
- pinMode(2,INPUT_PULLUP);
- Ethernet.begin(mac, ip);
- server.begin();
- Serial.begin(9600);
- }
- //=====================================================================================LOOP INFINITO PROGRAMA=================================================================//
- void loop(){
- EthernetClient client = server.available();
- if (client) {
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- if (readString.length() < 100) {
- readString += c;
- }
- if (c == '\n') {
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Refresh: 2"); //ATUALIZA O HTML DE 2 EM 2 SEGUNDOS
- client.println();
- client.println("<HTML>");
- client.println("<BODY>");
- client.println("<TITLE>SUPERVISORIO</TITLE>");
- client.println("<H1><center>SUPERVISORIO.</center></H1>");
- client.println("<hr />");
- client.println("<br />");
- client.println("<table border='1' width='17%'>");
- client.println("<tr>");
- client.println("<td width='103' align='center'>LED 1</td>");
- if (digitalRead(7)==1)
- client.println("<td align='center'>ON</td>");
- else
- client.println("<td align='center'>OFF</td>");
- client.println("</tr>");
- client.println("</table>");
- if (digitalRead(7)==HIGH)
- {
- client.println("<a href=\"/?ledoff\"\">Desligar o led</a><br />");
- }
- else
- {
- client.println("<a href=\"/?ledon\"\">Ligar o led</a>");
- }
- /*
- client.println("<a href=\"/?ledon\"\">Ligar o led</a>");
- client.println("<br />");
- client.println("<a href=\"/?ledoff\"\">Desligar o led</a><br />");*/
- client.println("</BODY>");
- client.println("</HTML>");
- delay(1);
- client.stop();
- if(readString.indexOf("?ledon") > 0)
- {
- digitalWrite(7, HIGH);
- }
- else {
- if(readString.indexOf("?ledoff") > 0)
- {
- digitalWrite(7, LOW);
- }
- }
- readString="";
- if (digitalRead(2)== LOW)
- {
- while (digitalRead(2) == LOW)
- {
- delay(30); // Delay para evitar debouncing
- digitalWrite(7, !(digitalRead(7))); /// Se tiver ON fica OFF e se tiver OFF fica ON
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement