Advertisement
Space-G

RFID

Dec 7th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. //Programa : RFID - Controle de Acesso leitor RFID
  2. //Autor : FILIPEFLOP
  3.  
  4. #include <SPI.h>
  5. #include <MFRC522.h>
  6. #include <LiquidCrystal.h>
  7.  
  8. #define SS_PIN A5
  9. #define RST_PIN A1
  10. MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
  11.  
  12. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  13.  
  14. char st[20];
  15.  
  16. void setup()
  17. {
  18.   SPI.begin();      // Inicia  SPI bus
  19.   mfrc522.PCD_Init();   // Inicia MFRC522
  20.   //Define o nΓΊmero de colunas e linhas do LCD:  
  21.   lcd.begin(16, 2);  
  22.   mensageminicial();
  23. }
  24.  
  25. String last_ID = "";
  26. void loop()
  27. {
  28.   // Look for new cards
  29.   if ( ! mfrc522.PICC_IsNewCardPresent())
  30.   {
  31.     return;
  32.   }
  33.   // Select one of the cards
  34.   if ( ! mfrc522.PICC_ReadCardSerial())
  35.   {
  36.     return;
  37.   }
  38.   //Mostra UID na serial
  39.   String conteudo= "";
  40.   byte letra;
  41.   for (byte i = 0; i < mfrc522.uid.size; i++)
  42.   {
  43.      conteudo.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
  44.      conteudo.concat(String(mfrc522.uid.uidByte[i], HEX));
  45.   }
  46.   conteudo.toUpperCase();
  47.   lcd.setCursor(0, 1);
  48.   if(conteudo.substring(1) != last_ID){
  49.     lcd.clear();
  50.     lcd.setCursor(0, 0);
  51.     lcd.print("Ant. ");
  52.     lcd.print(last_ID);
  53.     lcd.setCursor(0,1);
  54.     lcd.print(conteudo.substring(1));
  55.     last_ID = conteudo.substring(1);
  56.   }
  57.   delay(200);
  58.  
  59. }
  60.  
  61. void mensageminicial()
  62. {
  63.   lcd.clear();
  64.   lcd.print(" Aproxime o seu");  
  65.   lcd.setCursor(0,1);
  66.   lcd.print("cartao do leitor");  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement