Guest User

Mega_Automation_Serial+Bth

a guest
Oct 31st, 2016
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <IRremote.h>
  2. #include <IRremoteInt.h>
  3.  
  4. IRsend irsend;
  5.  
  6. const int RECV_PIN = 2;
  7. const int Rele = 8;
  8. IRrecv irrecv(RECV_PIN);
  9. decode_results results;
  10.  
  11. int led = 9;
  12. int ch1 = 3;
  13. int ch2 = 5;
  14. int ch3 = 6;
  15. int ch4 = 4;
  16. /// Home Teather//
  17. 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,};
  18. 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,};
  19. 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,};
  20. 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,};
  21. 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,};
  22. 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,};
  23. 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,};
  24. 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,};
  25. 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,};
  26. /// ar condicionado
  27. 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,};
  28. 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,};
  29. 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,};
  30. 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,};
  31. 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,};
  32. 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,};
  33.  
  34. //---------------------------------------------------------
  35. void setup()
  36. {
  37.   Serial3.begin(9600);
  38.   Serial.begin(9600);
  39.   pinMode(led, OUTPUT); //infravermelho;
  40.   pinMode(ch1, OUTPUT);//Pino digital saída do Arduino(4-ch1);
  41.   pinMode(ch2, OUTPUT);//Pino digital saída do Arduino(5-ch2);
  42.   pinMode(ch3, OUTPUT);//Pino digital saída do Arduino(6-ch3);
  43.   pinMode(ch4, OUTPUT);//Pino digital saída do Arduino(7-ch4);
  44.  
  45.   pinMode(Rele, OUTPUT);
  46.   irrecv.enableIRIn();
  47. }
  48. //---------------------------------------------------------
  49.  
  50.  
  51. void loop() {
  52.  
  53.   if (irrecv.decode(&results))
  54.   {
  55.     Serial.println(results.value, HEX);
  56.     if (results.value == 0xFF946B) // LIGA QUARTO//
  57.     {
  58.       digitalWrite(ch1, HIGH);
  59.     }
  60.     if (results.value == 0xFF0CF3) // DESLIGA QUARTO
  61.     {
  62.       digitalWrite(ch1, LOW);
  63.     }
  64.  
  65.     if (results.value == 0xFF8C73) // LIGA BANHEIRO//
  66.     {
  67.       digitalWrite(ch4, HIGH);
  68.     }
  69.     if (results.value == 0xFF4CB3) // DESLIGA BANHEIRO //
  70.     {
  71.       digitalWrite(ch4, LOW);
  72.     }
  73.  
  74.  
  75.     irrecv.resume();
  76.   }
  77.   if (Serial.available() > 0 || Serial3.available() > 0)
  78.   {
  79.     char valorlido;
  80.     if (Serial.available() > 0) valorlido = Serial.read(); //se ouver algo na serial usb receba esse
  81.     if (Serial3.available() > 0) valorlido = Serial3.read(); //se ouver algo na serial bth receba esse
  82.  
  83.     switch (valorlido)
  84.     {
  85.       // controle Receptor ///
  86.       case 'E': irsend.sendNEC (0xFF50AF, 32); break; // Power break;
  87.       case 'F': irsend.sendNEC (0xFFB04F, 32); break; // Botao OK ;
  88.       case 'P': irsend.sendNEC (0xFF8877, 32); break; // SETA PRA DIREITA  ;
  89.       case 'Q': irsend.sendNEC (0xFF08F7, 32); break; // SETA PRA ESQUERDA  ;
  90.       case 'R': irsend.sendNEC (0xFFD02F, 32); break; // SETA PRA CIMA  ;
  91.       case 'S': irsend.sendNEC (0xFF708F, 32); break; // SETA PRA BAIXO  ;
  92.       case 'T': irsend.sendNEC (0xFF7887, 32); break; // EXIT  ;
  93.       case 'U': irsend.sendNEC (0xFF6C93, 32); break; // SLEEP  ;
  94.       case 'V': irsend.sendNEC (0xFF58A7, 32); break; // MENU  ;
  95.       case 'W': irsend.sendNEC (0xFFEA15, 32); break; // FAVORITO  ;
  96.       case 'B': irsend.sendNEC (0xFFCC33, 32); break; // MUDO ;
  97.       case 'n': irsend.sendNEC (0xFF2CD3, 32); break; // tv radio ;
  98.       case 'o': irsend.sendNEC (0xFF807F, 32); break; // 1 ;
  99.       case 'p': irsend.sendNEC (0xFF40BF, 32); break; // 2 ;
  100.       case 'q': irsend.sendNEC (0xFFC03F, 32); break; // 3 ;
  101.       case 'r': irsend.sendNEC (0xFF20DF, 32); break; // 4 ;
  102.       case 's': irsend.sendNEC (0xFFA05F, 32); break; // 5 ;
  103.       case 't': irsend.sendNEC (0xFF609F, 32); break; // 6 ;
  104.       case 'u': irsend.sendNEC (0xFFE01F, 32); break; // 7 ;
  105.       case 'v': irsend.sendNEC (0xFF10EF, 32); break; // 8 ;
  106.       case 'y': irsend.sendNEC (0xFF906F, 32); break; // 9 ;
  107.       case 'C': irsend.sendNEC (0xFF00FF, 32); break; // 0 ;
  108.  
  109.       //Controle da tv //
  110.       case 'a': irsend.sendNEC (0x2FD48B7, 32); break; // Power break;
  111.       case 'b': irsend.sendNEC (0x2FDF00F, 32); break; // Input;
  112.       case 'c': irsend.sendNEC (0x2FD01FE, 32); break; // Menu;
  113.       case 'd': irsend.sendNEC (0x2FD41BE, 32); break; // Tecla Cima;
  114.       case 'e': irsend.sendNEC (0x2FDC13E, 32); break; // Tecla Baixo;
  115.       case 'f': irsend.sendNEC (0x2FDB847, 32); break; // Tecla Esquerda;
  116.       case 'g': irsend.sendNEC (0x2FD9867, 32); break; // Tecla Direita;
  117.       case 'h': irsend.sendNEC (0x2FD58A7, 32); break; // Volume +;
  118.       case 'i': irsend.sendNEC (0x2FD7887, 32); break; // Volume -;
  119.       case 'j': irsend.sendNEC (0x2FD1AE5, 32); break; // Exit;
  120.       case 'k': irsend.sendNEC (0x2FD9B64, 32); break; // voltar;
  121.       case 'l': irsend.sendNEC (0x2FD08F7, 32); break; // Mute;
  122.       case 'z': irsend.sendNEC (0x2FD916E, 32); break; // Enter;
  123.       case 'D': irsend.sendNEC (0x2FDA857, 32); break; // Sleep:
  124.       case 'X': irsend.sendNEC (0x2FD54AB, 32); break; // Netflix:
  125.       //case 'A': irsend.sendNEC (0x2FD20DF, 32);break; // Sbt:
  126.       //case 'C': irsend.sendNEC (0x2FDE01F, 32);break; // Record:
  127.  
  128.       //Controle Home;
  129.       case 'G': irsend.sendRaw (S_pwr, 67, 38); break; // Power break;
  130.       case 'H': irsend.sendRaw (S_fca, 67, 38); break; // funcao;
  131.       case 'I': irsend.sendRaw (S_vol, 67, 38); break; // Volume - ;
  132.       case 'J': irsend.sendRaw (S_volm, 67, 38); break; // Volume +;
  133.       case 'K': irsend.sendRaw (S_ant, 67, 38); break; // anterior;
  134.       case 'L': irsend.sendRaw (S_ava, 67, 38); break; // avancar;
  135.       case 'M': irsend.sendRaw (S_pla, 67, 38); break; //play;
  136.       case 'N': irsend.sendRaw (S_cim, 67, 38); break; //cima;
  137.       case 'O': irsend.sendRaw (S_bai, 67, 38); break; //baixo;
  138.       ///Ar condicionado
  139.       case 'Y': irsend.sendRaw (des_ar, 59, 38); break; //Desligar
  140.       case 'A': irsend.sendRaw (modo_ar, 59, 38); break; //modo ok
  141.       case 'x': irsend.sendRaw (velocidade_ar, 61, 38); break; //velocidade Ok
  142.       case 'w': irsend.sendRaw (aumenta_ar, 59, 38); break; //aumenta ok
  143.       case 'Z': irsend.sendRaw (diminui_ar, 59, 38); break; //diminui
  144.       case 'm': irsend.sendRaw (lig_ar, 59, 38); break; //Ligar
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.       //LAMPADAS:
  152.  
  153.       //CANAL 1//
  154.       case '1': digitalWrite(ch1, !digitalRead(ch1)); break; //Quarto;
  155.       case '5': digitalWrite(ch2, !digitalRead(ch2)); break; //NULO;
  156.       case '3': digitalWrite(ch3, !digitalRead(ch3)); break; //escada;
  157.       case '4': digitalWrite(ch4, !digitalRead(ch4)); break; // Banheiro
  158.     }
  159.     irrecv.enableIRIn();
  160.   }
  161.   Serial.flush();//limpa serial
  162.   Serial3.flush();//limpa serial
  163.   delay(10);
  164.  
  165. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×