Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "RFID Reader"
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2024-06-12 11:35:29
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* read info about tag which is closed to rfid. */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <MFRC522.h> //https://github.com/miguelbalboa/rfid
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t rfid_MFRC522_IRQ_PIN_D5 = 5;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t rfid_MFRC522_RST_PIN_D4 = 4;
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t rfid_MFRC522_SPI_PIN_MOSI_D51 = 51;
- const uint8_t rfid_MFRC522_SPI_PIN_MISO_D50 = 50;
- const uint8_t rfid_MFRC522_SPI_PIN_SCLK_D52 = 52;
- const uint8_t rfid_MFRC522_SPI_PIN_CS_D53 = 53;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool rfid_MFRC522_RST_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float rfid_MFRC522_RST_PIN_D4_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- MFRC522 mfrc522(rfid_MFRC522_SPI_PIN_CS_D53, rfid_MFRC522_RST_PIN_D4); // Create MFRC522 instance
- void setup(void) {
- // Initialize serial communications with the PC
- Serial.begin(9600);
- while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
- // Initialize the SPI library
- SPI.begin();
- // Initialize the MFRC522
- mfrc522.PCD_Init();
- mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
- // Print a message indicating readiness to scan RFID tags or cards
- Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
- // Setup pin modes
- pinMode(rfid_MFRC522_IRQ_PIN_D5, INPUT_PULLUP);
- pinMode(rfid_MFRC522_RST_PIN_D4, OUTPUT);
- pinMode(rfid_MFRC522_SPI_PIN_CS_D53, OUTPUT);
- }
- void loop(void) {
- // Refresh output data
- updateOutputs();
- // Check 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 updateOutputs() {
- // Update the raw data to the physical pin
- digitalWrite(rfid_MFRC522_RST_PIN_D4, rfid_MFRC522_RST_PIN_D4_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement