Advertisement
RuiViana

salvaIR.h

May 13th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. uint16_t RECV_PIN = D7;
  2. IRrecv irrecv(RECV_PIN);
  3. decode_results results;
  4. unsigned long cod;
  5. unsigned int canguru;
  6. unsigned int fimDeCode;
  7. unsigned int addr = 0;
  8. bool tigre;
  9. bool grava = false;
  10. bool inicio1 = 1;
  11. int pulga = 0;
  12. int addrControl ;
  13. int displayRC;
  14. //-------------------------------------------
  15. void verifica()
  16. {
  17.   grava = true;
  18.   int EEPROM_Old;
  19.   //  Serial.println(addr);
  20.   {
  21.     for (int EEPROMaddr = pulga * 0x64 ; EEPROMaddr <= addr;)                                       // Busca todos enderecos
  22.     {
  23.       EEPROM.get(EEPROMaddr, EEPROM_Old);
  24.  
  25.       if (EEPROM_Old == cod)
  26.       {
  27.         Serial.println(" <-- Já tem este code gravado");
  28.         grava = false;
  29.       }
  30.       EEPROMaddr = EEPROMaddr + 4;
  31.     }
  32.   }
  33. }
  34. //---------------------------------------
  35. void guardaRC_Code()
  36. {
  37.   Serial.println("Aperte uma tecla do RC");
  38.   tigre = 0;
  39.   while (tigre == 0)
  40.   {
  41.     yield();
  42.     if (irrecv.decode(&results))
  43.     {
  44.       cod = results.value;
  45.       tigre = 1;
  46.       irrecv.resume();          // Receive the next value
  47.     }
  48.   }
  49.   Serial.print(" Lido " ); Serial.print(cod, HEX);
  50.   verifica();
  51.   if ( grava == true)
  52.   {
  53.     EEPROM.put(addr, cod);
  54.  
  55.     Serial.println(" ");
  56.     Serial.print("cod  "); Serial.print(cod, HEX); Serial.print(" salvo em  ");
  57.     Serial.println(addr);
  58.     Serial.println(" ");
  59.  
  60.     EEPROM.put(addr + 4, 0xDAD0DAD0);
  61.     EEPROM.commit();
  62.  //   EEPROM.get(addr, canguru);
  63.  
  64.     addr = addr  + 4;
  65.   }
  66.   Serial.println("Digite um valor na serial");
  67. }
  68. //--------------------------------------------------------
  69. void selectRC()
  70. {
  71.   while (inicio1 == 1)
  72.   {
  73.     yield();
  74.     if (Serial.available() > 0)
  75.     {
  76.       pulga = Serial.read();
  77.       pulga = pulga & 0x0F;
  78.       Serial.println(" ");
  79.       Serial.print("RC "); Serial.print(pulga, DEC); Serial.print(" selecionado,");
  80.       addr = pulga * 0x64;
  81.       Serial.print(" iniciando no end. "); Serial.println(pulga * 0x64, DEC);
  82.       Serial.println(" ");
  83.       inicio1 = 0;
  84.       addrControl = addr;
  85.     }
  86.   }
  87. }
  88. //--------------------------------------------------------
  89. void listaRC()
  90. {
  91.   addr = pulga * 0x64;
  92.   while ((displayRC != 0xDAD0DAD0) & (displayRC != 0xFFFFFFFF))
  93.   {
  94.     yield();
  95.     EEPROM.get(addr, displayRC);
  96.     Serial.print(addr);
  97.     Serial.print(" : ");
  98.     Serial.println(displayRC, HEX);
  99.     addr = addr + 4;
  100.   }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement