PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AccessControl.ino 25KB

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