Advertisement
Lucasx2020

Untitled

Apr 2nd, 2020
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.93 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 D9 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. #define COMMON_ANODE
  81.  
  82. #ifdef COMMON_ANODE
  83. #define LED_ON LOW
  84. #define LED_OFF HIGH
  85. #else
  86. #define LED_ON HIGH
  87. #define LED_OFF LOW
  88. #endif
  89.  
  90. #define redLed 7 // Set Led Pins
  91. #define greenLed 6
  92. #define blueLed 8
  93.  
  94. #define relay 4 // Set Relay Pin
  95. #define wipeB 3 // Button pin for WipeMode
  96.  
  97. bool programMode = false; // initialize programming mode to false
  98.  
  99. uint8_t successRead; // Variable integer to keep if we have Successful Read from Reader
  100.  
  101. byte storedCard[4]; // Stores an ID read from EEPROM
  102. byte readCard[4]; // Stores scanned ID read from RFID Module
  103. byte masterCard[4]; // Stores master card's ID read from EEPROM
  104.  
  105. // Create MFRC522 instance.
  106. #define SS_PIN 53
  107. #define RST_PIN 9
  108. MFRC522 mfrc522(SS_PIN, RST_PIN);
  109.  
  110. ///////////////////////////////////////// Setup ///////////////////////////////////
  111. void setup() {
  112. //Arduino Pin Configuration
  113. pinMode(redLed, OUTPUT);
  114. pinMode(greenLed, OUTPUT);
  115. pinMode(blueLed, OUTPUT);
  116. pinMode(wipeB, INPUT_PULLUP); // Ativar o resistor pull up do pino
  117. pinMode(relay, OUTPUT);
  118. // Cuidado com o comportamento do circuito do relé durante a redefinição ou o ciclo de energia do seu Arduino
  119. digitalWrite(relay, HIGH); // Verifique se a porta está trancada
  120. digitalWrite(redLed, LED_OFF); // Verifique se o led está desligado
  121. digitalWrite(greenLed, LED_OFF); //Verifique se o led está desligado
  122. digitalWrite(blueLed, LED_OFF); // Verifique se o led está desligado
  123.  
  124. //Protocol Configuration
  125. Serial.begin(9600); // Initialize serial communications with PC
  126. SPI.begin(); // MFRC522 Hardware uses SPI protocol
  127. mfrc522.PCD_Init(); // Initialize MFRC522 Hardware
  128.  
  129. //If you set Antenna Gain to Max it will increase reading distance
  130. //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
  131.  
  132. Serial.println(F("Access Control Example v0.1")); // For debugging purposes
  133. ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
  134.  
  135.  
  136. // Código de limpeza - Se o botão (wipeB) pressionado durante a instalação (ligada), limpa EEPROM
  137. if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground
  138. digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe
  139. Serial.println(F("Wipe Button Pressed"));
  140. Serial.println(F("You have 10 seconds to Cancel"));
  141. Serial.println(F("This will be remove all records and cannot be undone"));
  142. bool buttonState = monitorWipeButton(10000); // Give user enough time to cancel operation
  143. if (buttonState == true && digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM
  144. Serial.println(F("Starting Wiping EEPROM"));
  145. for (uint16_t x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address
  146. if (EEPROM.read(x) == 0) { //If EEPROM address 0
  147. // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM
  148. }
  149. else {
  150. EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS
  151. }
  152. }
  153. Serial.println(F("EEPROM Successfully Wiped"));
  154. digitalWrite(redLed, LED_OFF); // visualize a successful wipe
  155. delay(200);
  156. digitalWrite(redLed, LED_ON);
  157. delay(200);
  158. digitalWrite(redLed, LED_OFF);
  159. delay(200);
  160. digitalWrite(redLed, LED_ON);
  161. delay(200);
  162. digitalWrite(redLed, LED_OFF);
  163. }
  164. else {
  165. Serial.println(F("Wiping Cancelled")); // Show some feedback that the wipe button did not pressed for 15 seconds
  166. digitalWrite(redLed, LED_OFF);
  167. }
  168. }
  169. // Check if master card defined, if not let user choose a master card
  170. // This also useful to just redefine the Master Card
  171. // You can keep other EEPROM records just write other than 143 to EEPROM address 1
  172. // EEPROM address 1 should hold magical number which is '143'
  173. if (EEPROM.read(1) != 143) {
  174. Serial.println(F("No Master Card Defined"));
  175. Serial.println(F("Scan A PICC to Define as Master Card"));
  176. do {
  177. successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
  178. digitalWrite(blueLed, LED_ON); // Visualize Master Card need to be defined
  179. delay(200);
  180. digitalWrite(blueLed, LED_OFF);
  181. delay(200);
  182. }
  183. while (!successRead); // Program will not go further while you not get a successful read
  184. for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
  185. EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3
  186. }
  187. EEPROM.write(1, 143); // Write to EEPROM we defined Master Card.
  188. Serial.println(F("Master Card Defined"));
  189. }
  190. Serial.println(F("-------------------"));
  191. Serial.println(F("Master Card's UID"));
  192. for ( uint8_t i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM
  193. masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard
  194. Serial.print(masterCard[i], HEX);
  195. }
  196. Serial.println("");
  197. Serial.println(F("-------------------"));
  198. Serial.println(F("Everything is ready"));
  199. Serial.println(F("Waiting PICCs to be scanned"));
  200. cycleLeds(); // Everything ready lets give user some feedback by cycling leds
  201. }
  202.  
  203.  
  204. ///////////////////////////////////////// Main Loop ///////////////////////////////////
  205. void loop () {
  206. do {
  207. successRead = getID(); // define successRead para 1 quando lemos do leitor, caso contrário 0
  208. // Quando o dispositivo estiver em uso, se o botão de limpeza for pressionado por 10 segundos, inicialize a limpeza do cartão principal
  209. if (digitalRead(wipeB) == LOW) { // verifique se o botão está pressionado
  210. // Visualize que a operação normal é interrompida pressionando o botão wipe Vermelho é como mais Aviso ao usuário
  211. digitalWrite(redLed, LED_ON); // Verifique se o led está desligado
  212. digitalWrite(greenLed, LED_OFF); // Verifique se o led está desligado
  213. digitalWrite(blueLed, LED_OFF); //Verifique se o led está desligado
  214. // Give some feedback
  215. Serial.println(F("Wipe Button Pressed"));
  216. Serial.println(F("Master Card will be Erased! in 10 seconds"));
  217. bool buttonState = monitorWipeButton(10000); //Dê ao usuário tempo suficiente para cancelar a operação
  218. if (buttonState == true && digitalRead(wipeB) == LOW) { // Se o botão ainda estiver pressionado, limpe EEPROM
  219. EEPROM.write(1, 0); // Reset Magic Number.
  220. Serial.println(F("Master Card Erased from device"));
  221. Serial.println(F("Please reset to re-program Master Card"));
  222. while (1);
  223. }
  224. Serial.println(F("Master Card Erase Cancelled"));
  225. }
  226. if (programMode) {
  227. cycleLeds(); // O modo de programa percorre o vermelho verde azul aguardando a leitura de um novo cartão
  228. }
  229. else {
  230. normalModeOn(); // Modo normal, o LED azul de energia está aceso, todos os outros estão apagados
  231. }
  232. }
  233. while (!successRead); //o programa não irá além enquanto você não estiver obtendo uma leitura bem-sucedida
  234. if (programMode) {
  235. if ( isMaster(readCard) ) { //Quando estiver no modo de programa, verifique Primeiro Se o cartão principal foi digitalizado novamente para sair do modo de programa
  236. Serial.println(F("Master Card Scanned"));
  237. Serial.println(F("Exiting Program Mode"));
  238. Serial.println(F("-----------------------------"));
  239. programMode = false;
  240. return;
  241. }
  242. else {
  243. if ( findID(readCard) ) { // Se o cartão digitalizado for conhecido, exclua-o
  244. Serial.println(F("I know this PICC, removing..."));
  245. deleteID(readCard);
  246. Serial.println("-----------------------------");
  247. Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
  248. }
  249. else { // Se o cartão digitalizado não for conhecido, adicione-o
  250. Serial.println(F("I do not know this PICC, adding..."));
  251. writeID(readCard);
  252. Serial.println(F("-----------------------------"));
  253. Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
  254. }
  255. }
  256. }
  257. else {
  258. if ( isMaster(readCard)) { // se o ID dos cartões digitalizados corresponder ao ID dos cartões principais - entre no modo de programa
  259. programMode = true;
  260. Serial.println(F("Hello Master - Entered Program Mode"));
  261. uint8_t count = EEPROM.read(0); // Leia o primeiro byte da EEPROM que
  262. Serial.print(F("I have ")); // armazena o número de IDs na EEPROM
  263. Serial.print(count);
  264. Serial.print(F(" record(s) on EEPROM"));
  265. Serial.println("");
  266. Serial.println(F("Scan a PICC to ADD or REMOVE to EEPROM"));
  267. Serial.println(F("Scan Master Card again to Exit Program Mode"));
  268. Serial.println(F("-----------------------------"));
  269. }
  270. else {
  271. if ( findID(readCard) ) { // Caso contrário, verifique se o cartão está na EEPROM
  272. Serial.println(F("Welcome, You shall pass"));
  273. granted(5000); // Tempo Abra a fechadura da porta por 5000 ms
  274. }
  275. else { // Caso contrário, mostre que o ID não era válido
  276. Serial.println(F("You shall not pass"));
  277. denied();
  278. }
  279. }
  280. }
  281. }
  282.  
  283. ///////////////////////////////////////// Acesso concedido ///////////////////////////////////
  284. void granted ( uint16_t setDelay) {
  285. digitalWrite(blueLed, LED_OFF); // Desligue o LED azul
  286. digitalWrite(redLed, LED_OFF); // Desligue o LED vermelho
  287. digitalWrite(greenLed, LED_ON); // Desligue o LED verde
  288. digitalWrite(relay, LOW); // Destranque a porta!
  289. delay(setDelay); // Mantenha a trava da porta aberta por alguns segundos
  290. digitalWrite(relay, HIGH); //Porta de bloqueio
  291. delay(1000); // Mantenha o LED verde aceso por um segundo
  292. }
  293.  
  294. ///////////////////////////////////////// Acesso Negado ///////////////////////////////////
  295. void denied() {
  296. digitalWrite(greenLed, LED_OFF); // Verifique se o LED verde está apagado
  297. digitalWrite(blueLed, LED_OFF); // Verifique se o LED azul está apagado
  298. digitalWrite(redLed, LED_ON); // Acender o LED vermelho
  299. delay(1000);
  300. }
  301.  
  302.  
  303. ///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
  304. uint8_t getID() {
  305. // Getting ready for Reading PICCs
  306. if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
  307. return 0;
  308. }
  309. if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
  310. return 0;
  311. }
  312.  
  313. // Existem PICCs da Mifare com cuidados de UID de 4 ou 7 bytes se você usar PICC de 7 bytes
  314. // Acho que devemos assumir todos os PICCs, pois eles têm UID de 4 bytes
  315. // Até suportarmos PICCs de 7 bytes
  316. Serial.println(F("Scanned PICC's UID:"));
  317. for ( uint8_t i = 0; i < 4; i++) { //
  318. readCard[i] = mfrc522.uid.uidByte[i];
  319. Serial.print(readCard[i], HEX);
  320. }
  321. Serial.println("");
  322. mfrc522.PICC_HaltA(); // Stop reading
  323. return 1;
  324. }
  325.  
  326. void ShowReaderDetails() {
  327. // Get the MFRC522 software version
  328. byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
  329. Serial.print(F("MFRC522 Software Version: 0x"));
  330. Serial.print(v, HEX);
  331. if (v == 0x91)
  332. Serial.print(F(" = v1.0"));
  333. else if (v == 0x92)
  334. Serial.print(F(" = v2.0"));
  335. else
  336. Serial.print(F(" (unknown),probably a chinese clone?"));
  337. Serial.println("");
  338. // When 0x00 or 0xFF is returned, communication probably failed
  339. if ((v == 0x00) || (v == 0xFF)) {
  340. Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
  341. Serial.println(F("SYSTEM HALTED: Check connections."));
  342. // Visualize system is halted
  343. digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
  344. digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
  345. digitalWrite(redLed, LED_ON); // Turn on red LED
  346. while (true); // do not go further
  347. }
  348. }
  349.  
  350. /////////////////////////////////////////Ciclos de Leds (Modo Programa) ///////////////////////////////////
  351. void cycleLeds() {
  352. digitalWrite(redLed, LED_OFF); // Make sure red LED is off
  353. digitalWrite(greenLed, LED_ON); // Make sure green LED is on
  354. digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
  355. delay(200);
  356. digitalWrite(redLed, LED_OFF); // Make sure red LED is off
  357. digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
  358. digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
  359. delay(200);
  360. digitalWrite(redLed, LED_ON); // Make sure red LED is on
  361. digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
  362. digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
  363. delay(200);
  364. }
  365.  
  366. //////////////////////////////////////// Normal Mode Led ///////////////////////////////////
  367. void normalModeOn () {
  368. digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card
  369. digitalWrite(redLed, LED_OFF); // Make sure Red LED is off
  370. digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off
  371. digitalWrite(relay, HIGH); // Make sure Door is Locked
  372. }
  373.  
  374. //////////////////////////////////////// Read an ID from EEPROM //////////////////////////////
  375. void readID( uint8_t number ) {
  376. uint8_t start = (number * 4 ) + 2; // Figure out starting position
  377. for ( uint8_t i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes
  378. storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array
  379. }
  380. }
  381.  
  382. ///////////////////////////////////////// Add ID to EEPROM ///////////////////////////////////
  383. void writeID( byte a[] ) {
  384. if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before!
  385. uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
  386. uint8_t start = ( num * 4 ) + 6; // Figure out where the next slot starts
  387. num++; // Increment the counter by one
  388. EEPROM.write( 0, num ); // Write the new count to the counter
  389. for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
  390. EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position
  391. }
  392. successWrite();
  393. Serial.println(F("Succesfully added ID record to EEPROM"));
  394. }
  395. else {
  396. failedWrite();
  397. Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
  398. }
  399. }
  400.  
  401. ///////////////////////////////////////// Remove ID from EEPROM ///////////////////////////////////
  402. void deleteID( byte a[] ) {
  403. if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card!
  404. failedWrite(); // If not
  405. Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
  406. }
  407. else {
  408. uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
  409. uint8_t slot; // Figure out the slot number of the card
  410. uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts
  411. uint8_t looping; // The number of times the loop repeats
  412. uint8_t j;
  413. uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards
  414. slot = findIDSLOT( a ); // Figure out the slot number of the card to delete
  415. start = (slot * 4) + 2;
  416. looping = ((num - slot) * 4);
  417. num--; // Decrement the counter by one
  418. EEPROM.write( 0, num ); // Write the new count to the counter
  419. for ( j = 0; j < looping; j++ ) { // Loop the card shift times
  420. EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM
  421. }
  422. for ( uint8_t k = 0; k < 4; k++ ) { // Shifting loop
  423. EEPROM.write( start + j + k, 0);
  424. }
  425. successDelete();
  426. Serial.println(F("Succesfully removed ID record from EEPROM"));
  427. }
  428. }
  429.  
  430. ///////////////////////////////////////// Check Bytes ///////////////////////////////////
  431. bool checkTwo ( byte a[], byte b[] ) {
  432. for ( uint8_t k = 0; k < 4; k++ ) { // Loop 4 times
  433. if ( a[k] != b[k] ) { // IF a != b then false, because: one fails, all fail
  434. return false;
  435. }
  436. }
  437. return true;
  438. }
  439.  
  440. ///////////////////////////////////////// Find Slot ///////////////////////////////////
  441. uint8_t findIDSLOT( byte find[] ) {
  442. uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
  443. for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
  444. readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
  445. if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
  446. // is the same as the find[] ID card passed
  447. return i; // The slot number of the card
  448. }
  449. }
  450. }
  451.  
  452. ///////////////////////////////////////// Find ID From EEPROM ///////////////////////////////////
  453. bool findID( byte find[] ) {
  454. uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
  455. for ( uint8_t i = 1; i < count; i++ ) { // Loop once for each EEPROM entry
  456. readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
  457. if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
  458. return true;
  459. }
  460. else { // If not, return false
  461. }
  462. }
  463. return false;
  464. }
  465.  
  466. ///////////////////////////////////////// Write Success to EEPROM ///////////////////////////////////
  467. // Flashes the green LED 3 times to indicate a successful write to EEPROM
  468. void successWrite() {
  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 on
  472. delay(200);
  473. digitalWrite(greenLed, LED_ON); // Make sure green LED is on
  474. delay(200);
  475. digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
  476. delay(200);
  477. digitalWrite(greenLed, LED_ON); // Make sure green LED is on
  478. delay(200);
  479. digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
  480. delay(200);
  481. digitalWrite(greenLed, LED_ON); // Make sure green LED is on
  482. delay(200);
  483. }
  484.  
  485. ///////////////////////////////////////// Write Failed to EEPROM ///////////////////////////////////
  486. // Flashes the red LED 3 times to indicate a failed write to EEPROM
  487. void failedWrite() {
  488. digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
  489. digitalWrite(redLed, LED_OFF); // Make sure red LED is off
  490. digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
  491. delay(200);
  492. digitalWrite(redLed, LED_ON); // Make sure red LED is on
  493. delay(200);
  494. digitalWrite(redLed, LED_OFF); // Make sure red LED is off
  495. delay(200);
  496. digitalWrite(redLed, LED_ON); // Make sure red LED is on
  497. delay(200);
  498. digitalWrite(redLed, LED_OFF); // Make sure red LED is off
  499. delay(200);
  500. digitalWrite(redLed, LED_ON); // Make sure red LED is on
  501. delay(200);
  502. }
  503.  
  504. ///////////////////////////////////////// Success Remove UID From EEPROM ///////////////////////////////////
  505. // Flashes the blue LED 3 times to indicate a success delete to EEPROM
  506. void successDelete() {
  507. digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
  508. digitalWrite(redLed, LED_OFF); // Make sure red LED is off
  509. digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
  510. delay(200);
  511. digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
  512. delay(200);
  513. digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
  514. delay(200);
  515. digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
  516. delay(200);
  517. digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
  518. delay(200);
  519. digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
  520. delay(200);
  521. }
  522.  
  523. ////////////////////// Check readCard IF is masterCard ///////////////////////////////////
  524. // Check to see if the ID passed is the master programing card
  525. bool isMaster( byte test[] ) {
  526. return checkTwo(test, masterCard);
  527. }
  528.  
  529. bool monitorWipeButton(uint32_t interval) {
  530. uint32_t now = (uint32_t)millis();
  531. while ((uint32_t)millis() - now < interval) {
  532. // check on every half a second
  533. if (((uint32_t)millis() % 500) == 0) {
  534. if (digitalRead(wipeB) != LOW)
  535. return false;
  536. }
  537. }
  538. return true;
  539. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement