Page 161 - 최강 아두이노 퍼스트 참고서
P. 161

#include <SPI.h>
                 #include <MFRC522.h>

                 #define RST_PIN     9       //
                 #define SS_PIN      10      //

                 MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

                 void setup() {
                     Serial.begin(9600);  //  Initialize  serial  communications  with  the  PC
                 SPI.begin();            // Init SPI bus     mfrc522.PCD_Init();   // Init MFRC522

                     ShowReaderDetails();    // Show details of PCD - MFRC522 Card Reader details

                     Serial.println("Scan PICC to see UID, type, and data blocks...");
                 }

                 void loop() {
                     //  Look  for  new  cards          if  (  !
                 mfrc522.PICC_IsNewCardPresent()) {         return;
                     }

                     //  Select  one  of  the  cards          if  (  !
                 mfrc522.PICC_ReadCardSerial()) {         return;
                     }

                     //  Dump  debug  info  about  the  card;  PICC_HaltA()  is  automatically  called
                 mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
                 }

                 void ShowReaderDetails() {
                     // Get the MFRC522 software version
                     byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
                     Serial.print("MFRC522  Software  Version:  0x");
                 Serial.print(v, HEX);     if (v == 0x91)












                                                   161
   156   157   158   159   160   161   162   163   164   165   166