Advertisement
LeventeDaradici

RFID Access Control

Mar 29th, 2022
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 24.27 KB | None | 0 0
  1. /*
  2.    --------------------------------------------------------------------------------------------------------------------
  3.    Example sketch/program showing An Arduino Door Access Control featuring RFID, EEPROM, Relay
  4.    --------------------------------------------------------------------------------------------------------------------
  5.    This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
  6.  
  7.    This example showing a complete Door Access Control System
  8.  
  9.   Simple Work Flow (not limited to) :
  10.                                      +---------+
  11.   +----------------------------------->READ TAGS+^------------------------------------------+
  12.   |                              +--------------------+                                     |
  13.   |                              |                    |                                     |
  14.   |                              |                    |                                     |
  15.   |                         +----v-----+        +-----v----+                                |
  16.   |                         |MASTER TAG|        |OTHER TAGS|                                |
  17.   |                         +--+-------+        ++-------------+                            |
  18.   |                            |                 |             |                            |
  19.   |                            |                 |             |                            |
  20.   |                      +-----v---+        +----v----+   +----v------+                     |
  21.   |         +------------+READ TAGS+---+    |KNOWN TAG|   |UNKNOWN TAG|                     |
  22.   |         |            +-+-------+   |    +-----------+ +------------------+              |
  23.   |         |              |           |                |                    |              |
  24.   |    +----v-----+   +----v----+   +--v--------+     +-v----------+  +------v----+         |
  25.   |    |MASTER TAG|   |KNOWN TAG|   |UNKNOWN TAG|     |GRANT ACCESS|  |DENY ACCESS|         |
  26.   |    +----------+   +---+-----+   +-----+-----+     +-----+------+  +-----+-----+         |
  27.   |                       |               |                 |               |               |
  28.   |       +----+     +----v------+     +--v---+             |               +--------------->
  29.   +-------+EXIT|     |DELETE FROM|     |ADD TO|             |                               |
  30.           +----+     |  EEPROM   |     |EEPROM|             |                               |
  31.                      +-----------+     +------+             +-------------------------------+
  32.  
  33.  
  34.    Use a Master Card which is act as Programmer then you can able to choose card holders who will granted access or not
  35.  
  36.  * **Easy User Interface**
  37.  
  38.    Just one RFID tag needed whether Delete or Add Tags. You can choose to use Leds for output or Serial LCD module to inform users.
  39.  
  40.  * **Stores Information on EEPROM**
  41.  
  42.    Information stored on non volatile Arduino's EEPROM memory to preserve Users' tag and Master Card. No Information lost
  43.    if power lost. EEPROM has unlimited Read cycle but roughly 100,000 limited Write cycle.
  44.  
  45.  * **Security**
  46.    To keep it simple we are going to use Tag's Unique IDs. It's simple and not hacker proof.
  47.  
  48.    @license Released into the public domain.
  49.  
  50.    Typical pin layout used:
  51.    -----------------------------------------------------------------------------------------
  52.                MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
  53.                Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
  54.    Signal      Pin          Pin           Pin       Pin        Pin              Pin
  55.    -----------------------------------------------------------------------------------------
  56.    RST/Reset   RST          9             5         -i        RESET/ICSP-5     RST
  57.    SPI SS      SDA(SS)      10            53        D10        10               10
  58.    SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
  59.    SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
  60.    SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
  61. */
  62.  
  63. #include <EEPROM.h>     // We are going to read and write PICC's UIDs from/to EEPROM
  64. #include <SPI.h>        // RC522 Module uses SPI protocol
  65. #include <MFRC522.h>  // Library for Mifare RC522 Devices
  66.  
  67. /*
  68.   Instead of a Relay you may want to use a servo. Servos can lock and unlock door locks too
  69.   Relay will be used by default
  70. */
  71.  
  72. // #include <Servo.h>
  73.  
  74. /*
  75.   For visualizing whats going on hardware we need some leds and to control door lock a relay and a wipe button
  76.   (or some other hardware) Used common anode led,digitalWriting HIGH turns OFF led Mind that if you are going
  77.   to use common cathode led or just seperate leds, simply comment out #define COMMON_ANODE,
  78. */
  79.  
  80.  
  81. #define LED_ON HIGH
  82. #define LED_OFF LOW
  83.  
  84.  
  85. #define redLed 7    // Set Led Pins
  86. #define greenLed 6
  87. #define blueLed 5
  88.  
  89. #define relay 4     // Set Relay Pin
  90. #define wipeB 3     // Button pin for WipeMode
  91.  
  92. bool programMode = false;  // initialize programming mode to false
  93.  
  94. uint8_t successRead;    // Variable integer to keep if we have Successful Read from Reader
  95.  
  96. byte storedCard[4];   // Stores an ID read from EEPROM
  97. byte readCard[4];   // Stores scanned ID read from RFID Module
  98. byte masterCard[4];   // Stores master card's ID read from EEPROM
  99.  
  100. // Create MFRC522 instance.
  101. #define SS_PIN 10
  102. #define RST_PIN 9
  103. MFRC522 mfrc522(SS_PIN, RST_PIN);
  104.  
  105. ///////////////////////////////////////// Setup ///////////////////////////////////
  106. void setup() {
  107.   //Arduino Pin Configuration
  108.   pinMode(redLed, OUTPUT);
  109.   pinMode(greenLed, OUTPUT);
  110.   pinMode(blueLed, OUTPUT);
  111.   pinMode(wipeB, INPUT_PULLUP);   // Enable pin's pull up resistor
  112.   pinMode(relay, OUTPUT);
  113.   //Be careful how relay circuit behave on while resetting or power-cycling your Arduino
  114.   digitalWrite(relay, HIGH);    // Make sure door is locked
  115.   digitalWrite(redLed, LED_OFF);  // Make sure led is off
  116.   digitalWrite(greenLed, LED_OFF);  // Make sure led is off
  117.   digitalWrite(blueLed, LED_OFF); // Make sure led is off
  118.  
  119.   //Protocol Configuration
  120.   Serial.begin(9600);  // Initialize serial communications with PC
  121.   SPI.begin();           // MFRC522 Hardware uses SPI protocol
  122.   mfrc522.PCD_Init();    // Initialize MFRC522 Hardware
  123.  
  124.   //If you set Antenna Gain to Max it will increase reading distance
  125.   //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
  126.  
  127.   Serial.println(F("Access Control Example v0.1"));   // For debugging purposes
  128.   ShowReaderDetails();  // Show details of PCD - MFRC522 Card Reader details
  129.  
  130.   //Wipe Code - If the Button (wipeB) Pressed while setup run (powered on) it wipes EEPROM
  131.   if (digitalRead(wipeB) == LOW) {  // when button pressed pin should get low, button connected to ground
  132.     digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe
  133.     Serial.println(F("Wipe Button Pressed"));
  134.     Serial.println(F("You have 10 seconds to Cancel"));
  135.     Serial.println(F("This will be remove all records and cannot be undone"));
  136.     bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation
  137.     if (buttonState == true && digitalRead(wipeB) == LOW) {    // If button still be pressed, wipe EEPROM
  138.       Serial.println(F("Starting Wiping EEPROM"));
  139.       for (uint16_t x = 0; x < EEPROM.length(); x = x + 1) {    //Loop end of EEPROM address
  140.         if (EEPROM.read(x) == 0) {              //If EEPROM address 0
  141.           // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM
  142.         }
  143.         else {
  144.           EEPROM.write(x, 0);       // if not write 0 to clear, it takes 3.3mS
  145.         }
  146.       }
  147.       Serial.println(F("EEPROM Successfully Wiped"));
  148.       digitalWrite(redLed, LED_OFF);  // visualize a successful wipe
  149.       delay(200);
  150.       digitalWrite(redLed, LED_ON);
  151.       delay(200);
  152.       digitalWrite(redLed, LED_OFF);
  153.       delay(200);
  154.       digitalWrite(redLed, LED_ON);
  155.       delay(200);
  156.       digitalWrite(redLed, LED_OFF);
  157.     }
  158.     else {
  159.       Serial.println(F("Wiping Cancelled")); // Show some feedback that the wipe button did not pressed for 15 seconds
  160.       digitalWrite(redLed, LED_OFF);
  161.     }
  162.   }
  163.   // Check if master card defined, if not let user choose a master card
  164.   // This also useful to just redefine the Master Card
  165.   // You can keep other EEPROM records just write other than 143 to EEPROM address 1
  166.   // EEPROM address 1 should hold magical number which is '143'
  167.   if (EEPROM.read(1) != 143) {
  168.     Serial.println(F("No Master Card Defined"));
  169.     Serial.println(F("Scan A PICC to Define as Master Card"));
  170.     do {
  171.       successRead = getID();            // sets successRead to 1 when we get read from reader otherwise 0
  172.       digitalWrite(blueLed, LED_ON);    // Visualize Master Card need to be defined
  173.       delay(200);
  174.       digitalWrite(blueLed, LED_OFF);
  175.       delay(200);
  176.     }
  177.     while (!successRead);                  // Program will not go further while you not get a successful read
  178.     for ( uint8_t j = 0; j < 4; j++ ) {        // Loop 4 times
  179.       EEPROM.write( 2 + j, readCard[j] );  // Write scanned PICC's UID to EEPROM, start from address 3
  180.     }
  181.     EEPROM.write(1, 143);                  // Write to EEPROM we defined Master Card.
  182.     Serial.println(F("Master Card Defined"));
  183.   }
  184.   Serial.println(F("-------------------"));
  185.   Serial.println(F("Master Card's UID"));
  186.   for ( uint8_t i = 0; i < 4; i++ ) {          // Read Master Card's UID from EEPROM
  187.     masterCard[i] = EEPROM.read(2 + i);    // Write it to masterCard
  188.     Serial.print(masterCard[i], HEX);
  189.   }
  190.   Serial.println("");
  191.   Serial.println(F("-------------------"));
  192.   Serial.println(F("Everything is ready"));
  193.   Serial.println(F("Waiting PICCs to be scanned"));
  194.   cycleLeds();    // Everything ready lets give user some feedback by cycling leds
  195. }
  196.  
  197.  
  198. ///////////////////////////////////////// Main Loop ///////////////////////////////////
  199. void loop () {
  200.   do {
  201.     successRead = getID();  // sets successRead to 1 when we get read from reader otherwise 0
  202.     // When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping
  203.     if (digitalRead(wipeB) == LOW) { // Check if button is pressed
  204.       // Visualize normal operation is iterrupted by pressing wipe button Red is like more Warning to user
  205.       digitalWrite(redLed, LED_ON);  // Make sure led is off
  206.       digitalWrite(greenLed, LED_OFF);  // Make sure led is off
  207.       digitalWrite(blueLed, LED_OFF); // Make sure led is off
  208.       // Give some feedback
  209.       Serial.println(F("Wipe Button Pressed"));
  210.       Serial.println(F("Master Card will be Erased! in 10 seconds"));
  211.       bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation
  212.       if (buttonState == true && digitalRead(wipeB) == LOW) {    // If button still be pressed, wipe EEPROM
  213.         EEPROM.write(1, 0);                  // Reset Magic Number.
  214.         Serial.println(F("Master Card Erased from device"));
  215.         Serial.println(F("Please reset to re-program Master Card"));
  216.         while (1);
  217.       }
  218.       Serial.println(F("Master Card Erase Cancelled"));
  219.     }
  220.     if (programMode) {
  221.       cycleLeds();              // Program Mode cycles through Red Green Blue waiting to read a new card
  222.     }
  223.     else {
  224.       normalModeOn();     // Normal mode, blue Power LED is on, all others are off
  225.     }
  226.   }
  227.   while (!successRead);   //the program will not go further while you are not getting a successful read
  228.   if (programMode) {
  229.     if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode
  230.       Serial.println(F("Master Card Scanned"));
  231.       Serial.println(F("Exiting Program Mode"));
  232.       Serial.println(F("-----------------------------"));
  233.       programMode = false;
  234.       return;
  235.     }
  236.     else {
  237.       if ( findID(readCard) ) { // If scanned card is known delete it
  238.         Serial.println(F("I know this PICC, removing..."));
  239.         deleteID(readCard);
  240.         Serial.println("-----------------------------");
  241.         Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
  242.       }
  243.       else {                    // If scanned card is not known add it
  244.         Serial.println(F("I do not know this PICC, adding..."));
  245.         writeID(readCard);
  246.         Serial.println(F("-----------------------------"));
  247.         Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
  248.       }
  249.     }
  250.   }
  251.   else {
  252.     if ( isMaster(readCard)) {    // If scanned card's ID matches Master Card's ID - enter program mode
  253.       programMode = true;
  254.       Serial.println(F("Hello Master - Entered Program Mode"));
  255.       uint8_t count = EEPROM.read(0);   // Read the first Byte of EEPROM that
  256.       Serial.print(F("I have "));     // stores the number of ID's in EEPROM
  257.       Serial.print(count);
  258.       Serial.print(F(" record(s) on EEPROM"));
  259.       Serial.println("");
  260.       Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
  261.       Serial.println(F("Scan Master Card again to Exit Program Mode"));
  262.       Serial.println(F("-----------------------------"));
  263.     }
  264.     else {
  265.       if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
  266.         Serial.println(F("Welcome, You shall pass"));
  267.         granted(1000);         // Open the door lock for 300 ms
  268.       }
  269.       else {      // If not, show that the ID was not valid
  270.         Serial.println(F("You shall not pass"));
  271.         denied();
  272.       }
  273.     }
  274.   }
  275. }
  276.  
  277. /////////////////////////////////////////  Access Granted    ///////////////////////////////////
  278. void granted ( uint16_t setDelay) {
  279.   digitalWrite(blueLed, LED_OFF);   // Turn off blue LED
  280.   digitalWrite(redLed, LED_OFF);  // Turn off red LED
  281.   digitalWrite(greenLed, LED_ON);   // Turn on green LED
  282.   digitalWrite(relay, LOW);     // Unlock door!
  283.   delay(setDelay);          // Hold door lock open for given seconds
  284.   digitalWrite(relay, HIGH);    // Relock door
  285.   delay(1000);            // Hold green LED on for a second
  286. }
  287.  
  288. ///////////////////////////////////////// Access Denied  ///////////////////////////////////
  289. void denied() {
  290.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  291.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  292.   digitalWrite(redLed, LED_ON);   // Turn on red LED
  293.   delay(1000);
  294. }
  295.  
  296.  
  297. ///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
  298. uint8_t getID() {
  299.   // Getting ready for Reading PICCs
  300.   if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
  301.     return 0;
  302.   }
  303.   if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
  304.     return 0;
  305.   }
  306.   // There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC
  307.   // I think we should assume every PICC as they have 4 byte UID
  308.   // Until we support 7 byte PICCs
  309.   Serial.println(F("Scanned PICC's UID:"));
  310.   for ( uint8_t i = 0; i < 4; i++) {  //
  311.     readCard[i] = mfrc522.uid.uidByte[i];
  312.     Serial.print(readCard[i], HEX);
  313.   }
  314.   Serial.println("");
  315.   mfrc522.PICC_HaltA(); // Stop reading
  316.   return 1;
  317. }
  318.  
  319. void ShowReaderDetails() {
  320.   // Get the MFRC522 software version
  321.   byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
  322.   Serial.print(F("MFRC522 Software Version: 0x"));
  323.   Serial.print(v, HEX);
  324.   if (v == 0x91)
  325.     Serial.print(F(" = v1.0"));
  326.   else if (v == 0x92)
  327.     Serial.print(F(" = v2.0"));
  328.   else
  329.     Serial.print(F(" (unknown),probably a chinese clone?"));
  330.   Serial.println("");
  331.   // When 0x00 or 0xFF is returned, communication probably failed
  332.   if ((v == 0x00) || (v == 0xFF)) {
  333.     Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
  334.     Serial.println(F("SYSTEM HALTED: Check connections."));
  335.     // Visualize system is halted
  336.     digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  337.     digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  338.     digitalWrite(redLed, LED_ON);   // Turn on red LED
  339.     while (true); // do not go further
  340.   }
  341. }
  342.  
  343. ///////////////////////////////////////// Cycle Leds (Program Mode) ///////////////////////////////////
  344. void cycleLeds() {
  345.   digitalWrite(redLed, LED_OFF);  // Make sure red LED is off
  346.   digitalWrite(greenLed, LED_ON);   // Make sure green LED is on
  347.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  348.   delay(200);
  349.   digitalWrite(redLed, LED_OFF);  // Make sure red LED is off
  350.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  351.   digitalWrite(blueLed, LED_ON);  // Make sure blue LED is on
  352.   delay(200);
  353.   digitalWrite(redLed, LED_ON);   // Make sure red LED is on
  354.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  355.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  356.   delay(200);
  357. }
  358.  
  359. //////////////////////////////////////// Normal Mode Led  ///////////////////////////////////
  360. void normalModeOn () {
  361.   digitalWrite(blueLed, LED_ON);  // Blue LED ON and ready to read card
  362.   digitalWrite(redLed, LED_OFF);  // Make sure Red LED is off
  363.   digitalWrite(greenLed, LED_OFF);  // Make sure Green LED is off
  364.   digitalWrite(relay, HIGH);    // Make sure Door is Locked
  365. }
  366.  
  367. //////////////////////////////////////// Read an ID from EEPROM //////////////////////////////
  368. void readID( uint8_t number ) {
  369.   uint8_t start = (number * 4 ) + 2;    // Figure out starting position
  370.   for ( uint8_t i = 0; i < 4; i++ ) {     // Loop 4 times to get the 4 Bytes
  371.     storedCard[i] = EEPROM.read(start + i);   // Assign values read from EEPROM to array
  372.   }
  373. }
  374.  
  375. ///////////////////////////////////////// Add ID to EEPROM   ///////////////////////////////////
  376. void writeID( byte a[] ) {
  377.   if ( !findID( a ) ) {     // Before we write to the EEPROM, check to see if we have seen this card before!
  378.     uint8_t num = EEPROM.read(0);     // Get the numer of used spaces, position 0 stores the number of ID cards
  379.     uint8_t start = ( num * 4 ) + 6;  // Figure out where the next slot starts
  380.     num++;                // Increment the counter by one
  381.     EEPROM.write( 0, num );     // Write the new count to the counter
  382.     for ( uint8_t j = 0; j < 4; j++ ) {   // Loop 4 times
  383.       EEPROM.write( start + j, a[j] );  // Write the array values to EEPROM in the right position
  384.     }
  385.     successWrite();
  386.     Serial.println(F("Succesfully added ID record to EEPROM"));
  387.   }
  388.   else {
  389.     failedWrite();
  390.     Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
  391.   }
  392. }
  393.  
  394. ///////////////////////////////////////// Remove ID from EEPROM   ///////////////////////////////////
  395. void deleteID( byte a[] ) {
  396.   if ( !findID( a ) ) {     // Before we delete from the EEPROM, check to see if we have this card!
  397.     failedWrite();      // If not
  398.     Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
  399.   }
  400.   else {
  401.     uint8_t num = EEPROM.read(0);   // Get the numer of used spaces, position 0 stores the number of ID cards
  402.     uint8_t slot;       // Figure out the slot number of the card
  403.     uint8_t start;      // = ( num * 4 ) + 6; // Figure out where the next slot starts
  404.     uint8_t looping;    // The number of times the loop repeats
  405.     uint8_t j;
  406.     uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards
  407.     slot = findIDSLOT( a );   // Figure out the slot number of the card to delete
  408.     start = (slot * 4) + 2;
  409.     looping = ((num - slot) * 4);
  410.     num--;      // Decrement the counter by one
  411.     EEPROM.write( 0, num );   // Write the new count to the counter
  412.     for ( j = 0; j < looping; j++ ) {         // Loop the card shift times
  413.       EEPROM.write( start + j, EEPROM.read(start + 4 + j));   // Shift the array values to 4 places earlier in the EEPROM
  414.     }
  415.     for ( uint8_t k = 0; k < 4; k++ ) {         // Shifting loop
  416.       EEPROM.write( start + j + k, 0);
  417.     }
  418.     successDelete();
  419.     Serial.println(F("Succesfully removed ID record from EEPROM"));
  420.   }
  421. }
  422.  
  423. ///////////////////////////////////////// Check Bytes   ///////////////////////////////////
  424. bool checkTwo ( byte a[], byte b[] ) {  
  425.   for ( uint8_t k = 0; k < 4; k++ ) {   // Loop 4 times
  426.     if ( a[k] != b[k] ) {     // IF a != b then false, because: one fails, all fail
  427.        return false;
  428.     }
  429.   }
  430.   return true;  
  431. }
  432.  
  433. ///////////////////////////////////////// Find Slot   ///////////////////////////////////
  434. uint8_t findIDSLOT( byte find[] ) {
  435.   uint8_t count = EEPROM.read(0);       // Read the first Byte of EEPROM that
  436.   for ( uint8_t i = 1; i <= count; i++ ) {    // Loop once for each EEPROM entry
  437.     readID(i);                // Read an ID from EEPROM, it is stored in storedCard[4]
  438.     if ( checkTwo( find, storedCard ) ) {   // Check to see if the storedCard read from EEPROM
  439.       // is the same as the find[] ID card passed
  440.       return i;         // The slot number of the card
  441.     }
  442.   }
  443. }
  444.  
  445. ///////////////////////////////////////// Find ID From EEPROM   ///////////////////////////////////
  446. bool findID( byte find[] ) {
  447.   uint8_t count = EEPROM.read(0);     // Read the first Byte of EEPROM that
  448.   for ( uint8_t i = 1; i < count; i++ ) {    // Loop once for each EEPROM entry
  449.     readID(i);          // Read an ID from EEPROM, it is stored in storedCard[4]
  450.     if ( checkTwo( find, storedCard ) ) {   // Check to see if the storedCard read from EEPROM
  451.       return true;
  452.     }
  453.     else {    // If not, return false
  454.     }
  455.   }
  456.   return false;
  457. }
  458.  
  459. ///////////////////////////////////////// Write Success to EEPROM   ///////////////////////////////////
  460. // Flashes the green LED 3 times to indicate a successful write to EEPROM
  461. void successWrite() {
  462.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  463.   digitalWrite(redLed, LED_OFF);  // Make sure red LED is off
  464.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is on
  465.   delay(200);
  466.   digitalWrite(greenLed, LED_ON);   // Make sure green LED is on
  467.   delay(200);
  468.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  469.   delay(200);
  470.   digitalWrite(greenLed, LED_ON);   // Make sure green LED is on
  471.   delay(200);
  472.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  473.   delay(200);
  474.   digitalWrite(greenLed, LED_ON);   // Make sure green LED is on
  475.   delay(200);
  476. }
  477.  
  478. ///////////////////////////////////////// Write Failed to EEPROM   ///////////////////////////////////
  479. // Flashes the red LED 3 times to indicate a failed write to EEPROM
  480. void failedWrite() {
  481.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  482.   digitalWrite(redLed, LED_OFF);  // Make sure red LED is off
  483.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  484.   delay(200);
  485.   digitalWrite(redLed, LED_ON);   // Make sure red LED is on
  486.   delay(200);
  487.   digitalWrite(redLed, LED_OFF);  // Make sure red LED is off
  488.   delay(200);
  489.   digitalWrite(redLed, LED_ON);   // Make sure red LED is on
  490.   delay(200);
  491.   digitalWrite(redLed, LED_OFF);  // Make sure red LED is off
  492.   delay(200);
  493.   digitalWrite(redLed, LED_ON);   // Make sure red LED is on
  494.   delay(200);
  495. }
  496.  
  497. ///////////////////////////////////////// Success Remove UID From EEPROM  ///////////////////////////////////
  498. // Flashes the blue LED 3 times to indicate a success delete to EEPROM
  499. void successDelete() {
  500.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  501.   digitalWrite(redLed, LED_OFF);  // Make sure red LED is off
  502.   digitalWrite(greenLed, LED_OFF);  // Make sure green LED is off
  503.   delay(200);
  504.   digitalWrite(blueLed, LED_ON);  // Make sure blue LED is on
  505.   delay(200);
  506.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  507.   delay(200);
  508.   digitalWrite(blueLed, LED_ON);  // Make sure blue LED is on
  509.   delay(200);
  510.   digitalWrite(blueLed, LED_OFF);   // Make sure blue LED is off
  511.   delay(200);
  512.   digitalWrite(blueLed, LED_ON);  // Make sure blue LED is on
  513.   delay(200);
  514. }
  515.  
  516. ////////////////////// Check readCard IF is masterCard   ///////////////////////////////////
  517. // Check to see if the ID passed is the master programing card
  518. bool isMaster( byte test[] ) {
  519.     return checkTwo(test, masterCard);
  520. }
  521.  
  522. bool monitorWipeButton(uint32_t interval) {
  523.   uint32_t now = (uint32_t)millis();
  524.   while ((uint32_t)millis() - now < interval)  {
  525.     // check on every half a second
  526.     if (((uint32_t)millis() % 500) == 0) {
  527.       if (digitalRead(wipeB) != LOW)
  528.         return false;
  529.     }
  530.   }
  531.   return true;
  532. }
  533.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement