Advertisement
Space-G

SD

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