Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CONTROLE REMOTO
- #include <IRremote.h>
- #include <SPI.h>
- #include <Ethernet.h> //W5100
- const int RECV_PIN = 2;
- IRsend irsend;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
- };
- IPAddress ip(192, 168, 1, 177);
- EthernetServer server(80);
- //RELES
- int pino_rele4 = 4; // Luz Quarto
- int pino_rele5 = 5; // Luz do banheiro
- /// Home Teather//
- unsigned int S_pwr[67] = {4500, 4350, 650, 1600, 600, 1600, 650, 450, 600, 500, 650, 500, 600, 500, 600, 1600, 600, 500, 650, 1600, 600, 1600, 600, 500, 600, 500, 650, 1600, 600, 500, 600, 1600, 650, 450, 600, 1650, 600, 500, 600, 500, 600, 500, 600, 500, 650, 450, 650, 500, 600, 500, 600, 500, 600, 1600, 600, 1650, 600, 1600, 600, 1600, 600, 1650, 600, 1600, 600, 1600, 650,};
- unsigned int S_fca[67] = {4550, 4350, 650, 1600, 600, 1600, 650, 450, 650, 450, 600, 550, 600, 500, 600, 1600, 650, 450, 600, 1650, 600, 1600, 600, 500, 600, 500, 650, 1600, 600, 500, 600, 1600, 650, 450, 600, 1650, 600, 500, 600, 500, 600, 500, 600, 1600, 600, 550, 600, 500, 600, 500, 600, 500, 650 , 1550, 650, 1600, 600, 1600, 600, 500, 650, 1600, 600, 1600, 600, 1600, 600,};
- unsigned int S_vol[67] = {4500, 4400, 600, 1650, 550, 1650, 600, 500, 600, 500, 600, 500, 600, 550, 600, 1600, 600, 500, 600, 1600, 600, 1650, 600, 500, 600, 500, 600, 1600, 600, 550, 600, 1600, 600, 500, 600, 1600, 600, 1650, 600, 500, 600, 1600, 600, 1650, 600, 1600, 600, 500, 600, 500, 600, 500, 600, 550, 600, 1600, 600, 500, 600, 500, 600, 550, 550, 1650, 600, 1600, 600,};
- unsigned int S_volm[67] = {4500, 4400, 600, 1600, 600, 1650, 600, 500, 600, 500, 600, 500, 600, 500, 600, 1650, 600, 500, 600, 1600, 600, 1650, 600, 500, 600, 500, 600, 1600, 600, 500, 600, 1650, 600, 500, 600, 1600, 600, 1650, 600, 500, 600, 500, 600, 1600, 600, 1650, 600, 500, 600, 500, 600, 500, 600, 500, 600, 1650, 600, 1600, 600, 500, 600, 500, 600, 1650, 600, 1600, 600,};
- unsigned int S_ant[67] = {4550, 4350, 600, 1600, 600, 1600, 650, 500, 600, 500, 600, 500, 650, 450, 650, 1600, 600, 500, 650, 1550, 650, 1600, 600, 500, 650, 450, 650, 1600, 600, 500, 600, 1600, 600, 500, 650, 1600, 600, 1600, 650, 450, 650, 1600, 600, 1600, 650, 450, 650, 500, 600, 500, 600, 500, 650, 450, 650, 1600, 600, 500, 600, 500, 600, 1600, 650, 1600, 650, 1550, 650,};
- unsigned int S_ava[67] = {4500, 4400, 550, 1650, 600, 1600, 600, 500, 600, 500, 600, 550, 600, 500, 600, 1600, 600, 500, 600, 1650, 600, 1600, 600, 500, 600, 500, 600, 1650, 600, 500, 600, 1600, 600, 500, 600, 1650, 600, 1600, 600, 500, 600, 500, 600, 1650, 600, 500, 550, 550, 600, 500, 600, 500, 600, 500, 600, 1650, 600, 1600, 600, 500, 600, 1650, 600, 1600, 550, 1650, 600,};
- unsigned int S_pla[67] = {4500, 4400, 550, 1650, 600, 1600, 600, 500, 600, 500, 600, 550, 600, 500, 600, 1600, 600, 500, 600, 1650, 600, 1600, 600, 500, 600, 500, 600, 1650, 600, 500, 600, 1600, 600, 500, 600, 1650, 600, 1600, 600, 500, 600, 500, 600, 1650, 600, 500, 550, 550, 600, 500, 600, 500, 600, 500, 600, 1650, 600, 1600, 600, 500, 600, 1650, 600, 1600, 550, 1650, 600,};
- unsigned int S_cim[67] = {4500, 4400, 550, 1700, 550, 1650, 550, 550, 550, 550, 550, 600, 550, 550, 550, 1650, 550, 550, 550, 1700, 550, 1650, 550, 550, 550, 550, 550, 1700, 550, 550, 550, 1650, 550, 600, 550, 1650, 550, 550, 550, 1650, 550, 1700, 550, 550, 550, 550, 550, 550, 550, 600, 550, 550, 550, 1650, 550, 550, 550, 600, 550, 1650, 550, 1650, 550, 1700, 550, 1650, 550,};
- unsigned int S_bai[67] = {4550, 4350, 650, 1600, 600, 1600, 650, 450, 600, 500, 650, 450, 650, 500, 600, 1600, 650, 450, 650, 1600, 600, 1600, 650, 450, 650, 450, 650, 1600, 600, 500, 650, 1550, 600, 500, 650, 1600, 600, 500, 650, 1550, 650, 500, 600, 500, 600, 500, 650, 450, 650, 450, 650, 500, 600, 1600, 600, 500, 650, 1550, 650, 1600, 600, 1600, 600, 1650, 600, 1600, 600,};
- /// ar condicionado
- unsigned int des_ar[59] = {3208, 9548, 608, 1444, 608, 412, 604, 408, 604, 408, 604, 1448, 604, 432, 604, 412, 604, 408, 608, 1420, 608, 1420, 604, 432, 584, 428, 608, 408, 604, 412, 604, 408, 608, 428, 584, 432, 580, 432, 580, 432, 584, 432, 580, 432, 584, 1444, 580, 432, 580, 1448, 492, 520, 524, 492, 604, 432, 584, 1444, 580,};
- unsigned int modo_ar[59] = {3168, 9640, 524, 1500, 576, 444, 548, 464, 548, 464, 552, 1476, 548, 488, 524, 488, 528, 488, 524, 488, 496, 516, 500, 516, 520, 496, 520, 1528, 524, 492, 520, 1508, 520, 492, 520, 496, 520, 492, 520, 1528, 500, 1556, 496, 516, 496, 1528, 500, 516, 572, 440, 496, 516, 500, 516, 496, 516, 552, 1476, 520,};
- unsigned int velocidade_ar[61] = {368, 43108, 3152, 9604, 580, 1472, 524, 492, 552, 460, 552, 460, 556, 1472, 552, 464, 576, 436, 576, 436, 580, 1448, 580, 456, 556, 1472, 556, 456, 580, 436, 576, 436, 608, 408, 604, 432, 580, 1448, 604, 432, 584, 1444, 580, 1448, 580, 436, 600, 1448, 580, 436, 572, 440, 572, 1456, 572, 468, 544, 468, 544, 1484, 544,};
- unsigned int aumenta_ar[59] = {3196, 9612, 572, 1452, 524, 516, 500, 512, 500, 516, 496, 1532, 520, 496, 520, 516, 496, 516, 572, 440, 576, 440, 572, 440, 576, 440, 548, 1476, 576, 436, 576, 464, 500, 516, 496, 1528, 500, 516, 496, 516, 576, 1456, 520, 492, 520, 1528, 500, 516, 496, 516, 500, 512, 576, 1452, 572, 440, 520, 1532, 500,};
- unsigned int diminui_ar[59] = {3184, 9624, 552, 1504, 524, 488, 584, 428, 584, 432, 584, 1468, 604, 436, 584, 428, 584, 432, 584, 428, 584, 428, 584, 432, 584, 428, 584, 1468, 584, 428, 584, 432, 584, 428, 540, 1488, 608, 432, 584, 428, 496, 516, 500, 516, 496, 1556, 584, 428, 584, 428, 500, 516, 596, 1432, 608, 428, 500, 516, 608,};
- unsigned int lig_ar[59] = {3124, 9636, 552, 1500, 524, 492, 576, 436, 576, 436, 552, 1500, 528, 516, 496, 516, 500, 512, 580, 436, 544, 468, 572, 444, 572, 440, 552, 460, 580, 436, 576, 1448, 524, 496, 520, 496, 520, 492, 520, 1528, 500, 1528, 500, 512, 500, 1528, 500, 512, 552, 1504, 576, 1448, 580, 436, 520, 1512, 520, 492, 520,};
- void setup() {
- Serial.begin(9600);
- pinMode(pino_rele4, OUTPUT); // Quarto
- pinMode(pino_rele5, OUTPUT); // banheiro
- //Desliga os reles
- digitalWrite(pino_rele4, HIGH); // Quarto
- digitalWrite(pino_rele5, HIGH); // banheiro
- while (!Serial) {
- ;
- }
- Ethernet.begin(mac, ip);
- server.begin();
- //Controle remoto mega pin 9
- pinMode(9,OUTPUT);
- digitalWrite(9, LOW);
- irrecv.enableIRIn();
- }
- void loop() {
- EthernetClient client = server.available();
- if (client) {
- boolean currentLineIsBlank = true;
- String vars;
- int acao = 0;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- vars.concat(c);
- ///Rele
- //AQUI ACONTECEM AS COMPARACOES(Receptor)
- if (vars.endsWith("/assistirtv")) acao=2;
- else if (vars.endsWith("/desligartv")) acao=3;
- else if (vars.endsWith("/ok")) acao=4;
- else if (vars.endsWith("/setadireita")) acao=5;
- else if (vars.endsWith("/setaesquerda")) acao=6;
- else if (vars.endsWith("/cima")) acao=7;
- else if (vars.endsWith("/baixo")) acao=8;
- else if (vars.endsWith("/8")) acao=20;
- else if (vars.endsWith("/9")) acao=21;
- else if (vars.endsWith("/0")) acao=22;
- // Rele
- else if (vars.endsWith("/luzquarto")) acao=20;
- else if (vars.endsWith("/luzbanheiro")) acao=21;
- Serial.write(c);
- if (c == '\n' && currentLineIsBlank) {
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println();
- client.println("<!doctype html>");
- client.println("<head>");
- client.println("<meta charset=\"utf-8\">");
- client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"");
- client.println("<title>Automação meu QUARTO</title>");
- client.println("<meta name=\"viewport\" content=\"width=320\">");
- client.println("<meta name=\"viewport\" content=\"width=device-width\">");
- client.println("<meta charset=\"utf-8\">");
- client.println("<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\">");
- client.println("</head>");
- client.println("<body>");
- client.println("<center>");
- client.println("<meta charset=\"utf-8\">");
- client.println("<font size=\"5\" face=\"verdana\" color=\"green\">AUTOMAÇÃO</font>");
- client.println("<font size=\"5\" face=\"verdana\" color=\"blue\"> QUARTO</font><br />");
- client.println("<form action=\"/assistirtv\" method=\"get\">");
- client.println("<button type=submit style=\"width:200px;\">Ligar TV - </button> ");
- client.println("</form> <br />");
- client.println("<form action=\"/cima\" method=\"get\">");
- client.println("<button type=submit style=\"width:200px;\">Cima - </button> ");
- client.println("</form> <br />");
- client.println("<form action=\"/baixo\" method=\"get\">");
- client.println("<button type=submit style=\"width:200px;\">baixo - </button> ");
- client.println("</form> <br />");
- client.println("");
- client.println("");
- client.println("");
- client.println("</center>");
- client.println("</body>");
- client.println("</html>");
- if (acao == 2){ //LIGANDO A TV
- //Ligar receptor
- irsend.sendNEC(0xFF50AF, 32);
- delay(2000);
- //ligar tv
- irsend.sendNEC(0x2FD48B7, 32);
- break;
- }
- else if (acao == 3){ //DESLIGANDO A TV
- //Ligar receptor
- irsend.sendNEC(0xFF50AF, 32);
- delay(2000);
- //ligar tv
- irsend.sendNEC(0x2FD48B7, 32);
- break;
- }
- else if (acao == 4){ //Ok
- irsend.sendNEC(0xFFB04F, 32);
- break;
- }
- else if (acao == 5){ //SetaDiretia
- irsend.sendNEC(0xFF8877, 32);
- break;
- }
- else if (acao == 6){ //seta esquerda
- irsend.sendNEC(0xFF08F7, 32);
- break;
- }
- else if (acao == 7){ //Seta cima
- irsend.sendNEC(0xFFD02F, 32);
- break;
- }
- else if (acao == 8){ //Seta baixo
- irsend.sendNEC(0xFF708F, 32);
- break;
- }
- else if (acao == 20) //Banheiro
- {
- digitalWrite(pino_rele5, !digitalRead(pino_rele5));
- break;
- }else if (acao == 21) //Quarto
- {
- digitalWrite(pino_rele4, !digitalRead(pino_rele4));
- break;
- }
- else
- {
- //NÃO FAZ NADA
- }
- break;
- }
- if (c == '\n') {
- currentLineIsBlank = true;
- } else if (c != '\r') {
- currentLineIsBlank = false;
- }// Final do if
- } //Final do if
- } // Final do while
- delay(1);
- irrecv.enableIRIn();
- client.stop();
- } //Final do if client
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement