Advertisement
ocneves

rfid_multi chave liga_desliga

Mar 1st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <MFRC522.h>
  3.  
  4. #define SS_PIN1 8
  5. #define SS_PIN2 10
  6. #define RST_PIN 9
  7.  
  8. MFRC522 mfrc522_1(SS_PIN1, RST_PIN); // Create MFRC522_1 instance.
  9. MFRC522 mfrc522_2(SS_PIN2, RST_PIN); // Create MFRC522_2 instance.
  10. int ledpin7 = 7;
  11. int ledpin5 = 5;
  12. char st[20];
  13. byte State = 0;
  14.  
  15. void setup()
  16. {
  17. Serial.begin(9600);
  18. SPI.begin(); // Inicia SPI bus
  19. mfrc522_1.PCD_Init(); // Inicia MFRC522_1
  20. mfrc522_2.PCD_Init(); // Inicia MFRC522_2
  21. pinMode (ledpin7 , OUTPUT);
  22. pinMode (ledpin5 , OUTPUT);
  23. }
  24.  
  25. void loop()
  26. {
  27. if( digitalRead(ledpin7) == HIGH )
  28. { Serial.println("y");
  29. delay(2000);
  30. }
  31.  
  32. if( digitalRead(ledpin5) == HIGH )
  33. { Serial.println("k");
  34. delay(2000);
  35. }
  36.  
  37.  
  38. // Select one of the cards
  39. if ( ! mfrc522_1.PICC_ReadCardSerial())
  40. if ( ! mfrc522_2.PICC_ReadCardSerial())
  41.  
  42. // Look for new cards
  43. if ( ! mfrc522_1.PICC_ReadCardSerial())
  44. {digitalWrite (ledpin7 , HIGH);
  45. }
  46. if ( ! mfrc522_2.PICC_ReadCardSerial())
  47. {
  48. // acende os leds
  49. digitalWrite (ledpin5 , HIGH);
  50. return ;
  51. }
  52.  
  53. //Serial.print("UID da tag :");
  54. String conteudo_1= "";
  55. String conteudo_2= "";
  56. byte letra;
  57.  
  58. for (byte i = 0; i < mfrc522_1.uid.size; i++)
  59. {
  60. //Serial.print(mfrc522_1.uid.uidByte[i] < 0x10 ? " 0" : " ");
  61. //Serial.print(mfrc522_1.uid.uidByte[i], HEX);
  62. conteudo_1.concat(String(mfrc522_1.uid.uidByte[i] < 0x10 ? " 0" : " "));
  63. conteudo_1.concat(String(mfrc522_1.uid.uidByte[i], HEX));
  64. }
  65.  
  66. for (byte i = 0; i < mfrc522_2.uid.size; i++)
  67. {
  68. //Serial.print(mfrc522_2.uid.uidByte[i] < 0x10 ? " 0" : " ");
  69. //Serial.print(mfrc522_2.uid.uidByte[i], HEX);
  70. conteudo_2.concat(String(mfrc522_2.uid.uidByte[i] < 0x10 ? " 0" : " "));
  71. conteudo_2.concat(String(mfrc522_2.uid.uidByte[i], HEX));
  72. }
  73.  
  74. conteudo_1.toUpperCase();
  75. conteudo_2.toUpperCase();
  76. if (conteudo_1.substring(1) == "E3 F5 31 DB") //UID Y - Chaveiro
  77. {
  78. digitalWrite (ledpin7 , LOW);
  79. //Serial.println("standby");
  80. }
  81. delay(200);
  82.  
  83. if (conteudo_2.substring(1) == "53 0A 6D D9") //UID K - Chaveiro
  84. {
  85. digitalWrite (ledpin5 , LOW);
  86. //Serial.println("standby");
  87. }
  88. delay(200);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement