Advertisement
lucasx2016

Untitled

Nov 9th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.01 KB | None | 0 0
  1. //CONTROLE REMOTO
  2. #include <IRremote.h>
  3.  
  4. #include <SPI.h>
  5. #include <Ethernet.h> //W5100
  6. const int RECV_PIN = 2;
  7. IRsend irsend;
  8. IRrecv irrecv(RECV_PIN);
  9. decode_results results;
  10.  
  11.  
  12.  
  13. byte mac[] = {
  14. 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  15. };
  16. IPAddress ip(192, 168, 1, 177);
  17.  
  18. EthernetServer server(80);
  19.  
  20. //RELES
  21. int pino_rele4 = 4; // Luz Quarto
  22. int pino_rele5 = 5; // Luz do banheiro
  23.  
  24.  
  25. /// Home Teather//
  26. 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,};
  27. 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,};
  28. 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,};
  29. 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,};
  30. 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,};
  31. 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,};
  32. 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,};
  33. 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,};
  34. 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,};
  35.  
  36. /// ar condicionado
  37. 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,};
  38. 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,};
  39. 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,};
  40. 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,};
  41. 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,};
  42. 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,};
  43.  
  44. void setup() {
  45.  
  46.  
  47.  
  48. Serial.begin(9600);
  49.  
  50. pinMode(pino_rele4, OUTPUT); // Quarto
  51.  
  52. pinMode(pino_rele5, OUTPUT); // banheiro
  53.  
  54. //Desliga os reles
  55. digitalWrite(pino_rele4, HIGH); // Quarto
  56. digitalWrite(pino_rele5, HIGH); // banheiro
  57.  
  58. while (!Serial) {
  59. ;
  60. }
  61.  
  62. Ethernet.begin(mac, ip);
  63. server.begin();
  64.  
  65. //Controle remoto mega pin 9
  66. pinMode(9,OUTPUT);
  67. digitalWrite(9, LOW);
  68. irrecv.enableIRIn();
  69.  
  70.  
  71.  
  72. }
  73.  
  74. void loop() {
  75.  
  76. EthernetClient client = server.available();
  77. if (client) {
  78.  
  79. boolean currentLineIsBlank = true;
  80.  
  81. String vars;
  82. int acao = 0;
  83.  
  84. while (client.connected()) {
  85. if (client.available()) {
  86. char c = client.read();
  87. vars.concat(c);
  88.  
  89. ///Rele
  90.  
  91. //AQUI ACONTECEM AS COMPARACOES(Receptor)
  92. if (vars.endsWith("/assistirtv")) acao=2;
  93. else if (vars.endsWith("/desligartv")) acao=3;
  94. else if (vars.endsWith("/ok")) acao=4;
  95. else if (vars.endsWith("/setadireita")) acao=5;
  96. else if (vars.endsWith("/setaesquerda")) acao=6;
  97. else if (vars.endsWith("/cima")) acao=7;
  98. else if (vars.endsWith("/baixo")) acao=8;
  99. else if (vars.endsWith("/8")) acao=20;
  100. else if (vars.endsWith("/9")) acao=21;
  101. else if (vars.endsWith("/0")) acao=22;
  102. // Rele
  103.  
  104.  
  105.  
  106.  
  107.  
  108. else if (vars.endsWith("/luzquarto")) acao=20;
  109. else if (vars.endsWith("/luzbanheiro")) acao=21;
  110.  
  111.  
  112.  
  113. Serial.write(c);
  114.  
  115. if (c == '\n' && currentLineIsBlank) {
  116.  
  117. client.println("HTTP/1.1 200 OK");
  118. client.println("Content-Type: text/html");
  119. client.println();
  120. client.println("<!doctype html>");
  121. client.println("<head>");
  122. client.println("<meta charset=\"utf-8\">");
  123. client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"");
  124. client.println("<title>Automação meu QUARTO</title>");
  125. client.println("<meta name=\"viewport\" content=\"width=320\">");
  126. client.println("<meta name=\"viewport\" content=\"width=device-width\">");
  127. client.println("<meta charset=\"utf-8\">");
  128. client.println("<meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=no\">");
  129. client.println("</head>");
  130. client.println("<body>");
  131. client.println("<center>");
  132. client.println("<meta charset=\"utf-8\">");
  133. client.println("<font size=\"5\" face=\"verdana\" color=\"green\">AUTOMAÇÃO</font>");
  134. client.println("<font size=\"5\" face=\"verdana\" color=\"blue\"> QUARTO</font><br />");
  135. client.println("<form action=\"/assistirtv\" method=\"get\">");
  136. client.println("<button type=submit style=\"width:200px;\">Ligar TV - </button> ");
  137. client.println("</form> <br />");
  138. client.println("<form action=\"/cima\" method=\"get\">");
  139. client.println("<button type=submit style=\"width:200px;\">Cima - </button> ");
  140. client.println("</form> <br />");
  141. client.println("<form action=\"/baixo\" method=\"get\">");
  142. client.println("<button type=submit style=\"width:200px;\">baixo - </button> ");
  143. client.println("</form> <br />");
  144.  
  145. client.println("");
  146. client.println("");
  147. client.println("");
  148.  
  149. client.println("</center>");
  150. client.println("</body>");
  151. client.println("</html>");
  152.  
  153.  
  154.  
  155.  
  156. if (acao == 2){ //LIGANDO A TV
  157. //Ligar receptor
  158. irsend.sendNEC(0xFF50AF, 32);
  159. delay(2000);
  160. //ligar tv
  161. irsend.sendNEC(0x2FD48B7, 32);
  162. break;
  163. }
  164. else if (acao == 3){ //DESLIGANDO A TV
  165. //Ligar receptor
  166. irsend.sendNEC(0xFF50AF, 32);
  167. delay(2000);
  168. //ligar tv
  169. irsend.sendNEC(0x2FD48B7, 32);
  170. break;
  171. }
  172. else if (acao == 4){ //Ok
  173.  
  174. irsend.sendNEC(0xFFB04F, 32);
  175. break;
  176. }
  177. else if (acao == 5){ //SetaDiretia
  178.  
  179. irsend.sendNEC(0xFF8877, 32);
  180. break;
  181. }
  182. else if (acao == 6){ //seta esquerda
  183.  
  184. irsend.sendNEC(0xFF08F7, 32);
  185. break;
  186. }
  187. else if (acao == 7){ //Seta cima
  188.  
  189. irsend.sendNEC(0xFFD02F, 32);
  190. break;
  191. }
  192. else if (acao == 8){ //Seta baixo
  193.  
  194. irsend.sendNEC(0xFF708F, 32);
  195. break;
  196. }
  197.  
  198.  
  199. else if (acao == 20) //Banheiro
  200. {
  201. digitalWrite(pino_rele5, !digitalRead(pino_rele5));
  202. break;
  203. }else if (acao == 21) //Quarto
  204. {
  205. digitalWrite(pino_rele4, !digitalRead(pino_rele4));
  206. break;
  207. }
  208. else
  209. {
  210. //NÃO FAZ NADA
  211. }
  212.  
  213. break;
  214. }
  215. if (c == '\n') {
  216.  
  217. currentLineIsBlank = true;
  218. } else if (c != '\r') {
  219.  
  220. currentLineIsBlank = false;
  221. }// Final do if
  222. } //Final do if
  223. } // Final do while
  224.  
  225. delay(1);
  226. irrecv.enableIRIn();
  227.  
  228.  
  229. client.stop();
  230. } //Final do if client
  231.  
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement