Modify int data types for cross platforms

This commit is contained in:
omersiar
2016-11-17 14:38:07 +02:00
parent a88d7e1ce6
commit 1a3ac748d0

View File

@@ -62,19 +62,19 @@
#include <EEPROM.h> // We are going to read and write PICC's UIDs from/to EEPROM #include <EEPROM.h> // We are going to read and write PICC's UIDs from/to EEPROM
#include <SPI.h> // RC522 Module uses SPI protocol #include <SPI.h> // RC522 Module uses SPI protocol
#include <MFRC522.h> // Library for Mifare RC522 Devices #include <MFRC522.h> // Library for Mifare RC522 Devices
/* /*
Instead of a Relay you may want to use a servo. Servos can lock and unlock door locks too Instead of a Relay you may want to use a servo. Servos can lock and unlock door locks too
Relay will be used by default Relay will be used by default
*/ */
// #include <Servo.h> // #include <Servo.h>
/* /*
For visualizing whats going on hardware we need some leds and to control door lock a relay and a wipe button For visualizing whats going on hardware we need some leds and to control door lock a relay and a wipe button
(or some other hardware) Used common anode led,digitalWriting HIGH turns OFF led Mind that if you are going (or some other hardware) Used common anode led,digitalWriting HIGH turns OFF led Mind that if you are going
to use common cathode led or just seperate leds, simply comment out #define COMMON_ANODE, to use common cathode led or just seperate leds, simply comment out #define COMMON_ANODE,
*/ */
#define COMMON_ANODE #define COMMON_ANODE
@@ -87,22 +87,22 @@
#define LED_OFF LOW #define LED_OFF LOW
#endif #endif
#define redLed 7 // Set Led Pins #define redLed 7 // Set Led Pins
#define greenLed 6 #define greenLed 6
#define blueLed 5 #define blueLed 5
#define relay 4 // Set Relay Pin #define relay 4 // Set Relay Pin
#define wipeB 3 // Button pin for WipeMode #define wipeB 3 // Button pin for WipeMode
boolean match = false; // initialize card match to false boolean match = false; // initialize card match to false
boolean programMode = false; // initialize programming mode to false boolean programMode = false; // initialize programming mode to false
boolean replaceMaster = false; boolean replaceMaster = false;
int successRead; // Variable integer to keep if we have Successful Read from Reader uint8_t successRead; // Variable integer to keep if we have Successful Read from Reader
byte storedCard[4]; // Stores an ID read from EEPROM byte storedCard[4]; // Stores an ID read from EEPROM
byte readCard[4]; // Stores scanned ID read from RFID Module byte readCard[4]; // Stores scanned ID read from RFID Module
byte masterCard[4]; // Stores master card's ID read from EEPROM byte masterCard[4]; // Stores master card's ID read from EEPROM
// Create MFRC522 instance. // Create MFRC522 instance.
#define SS_PIN 10 #define SS_PIN 10
@@ -115,16 +115,16 @@ void setup() {
pinMode(redLed, OUTPUT); pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT); pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT); pinMode(blueLed, OUTPUT);
pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor pinMode(wipeB, INPUT_PULLUP); // Enable pin's pull up resistor
pinMode(relay, OUTPUT); pinMode(relay, OUTPUT);
//Be careful how relay circuit behave on while resetting or power-cycling your Arduino //Be careful how relay circuit behave on while resetting or power-cycling your Arduino
digitalWrite(relay, HIGH); // Make sure door is locked digitalWrite(relay, HIGH); // Make sure door is locked
digitalWrite(redLed, LED_OFF); // Make sure led is off digitalWrite(redLed, LED_OFF); // Make sure led is off
digitalWrite(greenLed, LED_OFF); // Make sure led is off digitalWrite(greenLed, LED_OFF); // Make sure led is off
digitalWrite(blueLed, LED_OFF); // Make sure led is off digitalWrite(blueLed, LED_OFF); // Make sure led is off
//Protocol Configuration //Protocol Configuration
Serial.begin(9600); // Initialize serial communications with PC Serial.begin(9600); // Initialize serial communications with PC
SPI.begin(); // MFRC522 Hardware uses SPI protocol SPI.begin(); // MFRC522 Hardware uses SPI protocol
mfrc522.PCD_Init(); // Initialize MFRC522 Hardware mfrc522.PCD_Init(); // Initialize MFRC522 Hardware
@@ -132,27 +132,27 @@ void setup() {
//mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max); //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
Serial.println(F("Access Control Example v0.1")); // For debugging purposes Serial.println(F("Access Control Example v0.1")); // For debugging purposes
ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
//Wipe Code - If the Button (wipeB) Pressed while setup run (powered on) it wipes EEPROM //Wipe Code - If the Button (wipeB) Pressed while setup run (powered on) it wipes EEPROM
if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground if (digitalRead(wipeB) == LOW) { // when button pressed pin should get low, button connected to ground
digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe digitalWrite(redLed, LED_ON); // Red Led stays on to inform user we are going to wipe
Serial.println(F("Wipe Button Pressed")); Serial.println(F("Wipe Button Pressed"));
Serial.println(F("You have 15 seconds to Cancel")); Serial.println(F("You have 15 seconds to Cancel"));
Serial.println(F("This will be remove all records and cannot be undone")); Serial.println(F("This will be remove all records and cannot be undone"));
delay(15000); // Give user enough time to cancel operation delay(15000); // Give user enough time to cancel operation
if (digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM if (digitalRead(wipeB) == LOW) { // If button still be pressed, wipe EEPROM
Serial.println(F("Starting Wiping EEPROM")); Serial.println(F("Starting Wiping EEPROM"));
for (int x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address for (uint8_t x = 0; x < EEPROM.length(); x = x + 1) { //Loop end of EEPROM address
if (EEPROM.read(x) == 0) { //If EEPROM address 0 if (EEPROM.read(x) == 0) { //If EEPROM address 0
// do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM // do nothing, already clear, go to the next address in order to save time and reduce writes to EEPROM
} }
else { else {
EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS EEPROM.write(x, 0); // if not write 0 to clear, it takes 3.3mS
} }
} }
Serial.println(F("EEPROM Successfully Wiped")); Serial.println(F("EEPROM Successfully Wiped"));
digitalWrite(redLed, LED_OFF); // visualize a successful wipe digitalWrite(redLed, LED_OFF); // visualize a successful wipe
delay(200); delay(200);
digitalWrite(redLed, LED_ON); digitalWrite(redLed, LED_ON);
delay(200); delay(200);
@@ -182,7 +182,7 @@ void setup() {
delay(200); delay(200);
} }
while (!successRead); // Program will not go further while you not get a successful read while (!successRead); // Program will not go further while you not get a successful read
for ( int j = 0; j < 4; j++ ) { // Loop 4 times for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3 EEPROM.write( 2 + j, readCard[j] ); // Write scanned PICC's UID to EEPROM, start from address 3
} }
EEPROM.write(1, 143); // Write to EEPROM we defined Master Card. EEPROM.write(1, 143); // Write to EEPROM we defined Master Card.
@@ -190,7 +190,7 @@ void setup() {
} }
Serial.println(F("-------------------")); Serial.println(F("-------------------"));
Serial.println(F("Master Card's UID")); Serial.println(F("Master Card's UID"));
for ( int i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM for ( uint8_t i = 0; i < 4; i++ ) { // Read Master Card's UID from EEPROM
masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard masterCard[i] = EEPROM.read(2 + i); // Write it to masterCard
Serial.print(masterCard[i], HEX); Serial.print(masterCard[i], HEX);
} }
@@ -205,7 +205,7 @@ void setup() {
///////////////////////////////////////// Main Loop /////////////////////////////////// ///////////////////////////////////////// Main Loop ///////////////////////////////////
void loop () { void loop () {
do { do {
successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0 successRead = getID(); // sets successRead to 1 when we get read from reader otherwise 0
// When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping // When device is in use if wipe button pressed for 10 seconds initialize Master Card wiping
if (digitalRead(wipeB) == LOW) { // Check if button is pressed if (digitalRead(wipeB) == LOW) { // Check if button is pressed
// Visualize normal operation is iterrupted by pressing wipe button Red is like more Warning to user // Visualize normal operation is iterrupted by pressing wipe button Red is like more Warning to user
@@ -226,10 +226,10 @@ void loop () {
cycleLeds(); // Program Mode cycles through Red Green Blue waiting to read a new card cycleLeds(); // Program Mode cycles through Red Green Blue waiting to read a new card
} }
else { else {
normalModeOn(); // Normal mode, blue Power LED is on, all others are off normalModeOn(); // Normal mode, blue Power LED is on, all others are off
} }
} }
while (!successRead); //the program will not go further while you are not getting a successful read while (!successRead); //the program will not go further while you are not getting a successful read
if (programMode) { if (programMode) {
if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode if ( isMaster(readCard) ) { //When in program mode check First If master card scanned again to exit program mode
Serial.println(F("Master Card Scanned")); Serial.println(F("Master Card Scanned"));
@@ -254,11 +254,11 @@ void loop () {
} }
} }
else { else {
if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode if ( isMaster(readCard)) { // If scanned card's ID matches Master Card's ID - enter program mode
programMode = true; programMode = true;
Serial.println(F("Hello Master - Entered Program Mode")); Serial.println(F("Hello Master - Entered Program Mode"));
int count = EEPROM.read(0); // Read the first Byte of EEPROM that uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
Serial.print(F("I have ")); // stores the number of ID's in EEPROM Serial.print(F("I have ")); // stores the number of ID's in EEPROM
Serial.print(count); Serial.print(count);
Serial.print(F(" record(s) on EEPROM")); Serial.print(F(" record(s) on EEPROM"));
Serial.println(""); Serial.println("");
@@ -267,11 +267,11 @@ void loop () {
Serial.println(F("-----------------------------")); Serial.println(F("-----------------------------"));
} }
else { else {
if ( findID(readCard) ) { // If not, see if the card is in the EEPROM if ( findID(readCard) ) { // If not, see if the card is in the EEPROM
Serial.println(F("Welcome, You shall pass")); Serial.println(F("Welcome, You shall pass"));
granted(300); // Open the door lock for 300 ms granted(300); // Open the door lock for 300 ms
} }
else { // If not, show that the ID was not valid else { // If not, show that the ID was not valid
Serial.println(F("You shall not pass")); Serial.println(F("You shall not pass"));
denied(); denied();
} }
@@ -280,27 +280,27 @@ void loop () {
} }
///////////////////////////////////////// Access Granted /////////////////////////////////// ///////////////////////////////////////// Access Granted ///////////////////////////////////
void granted (int setDelay) { void granted ( uint16_t setDelay) {
digitalWrite(blueLed, LED_OFF); // Turn off blue LED digitalWrite(blueLed, LED_OFF); // Turn off blue LED
digitalWrite(redLed, LED_OFF); // Turn off red LED digitalWrite(redLed, LED_OFF); // Turn off red LED
digitalWrite(greenLed, LED_ON); // Turn on green LED digitalWrite(greenLed, LED_ON); // Turn on green LED
digitalWrite(relay, LOW); // Unlock door! digitalWrite(relay, LOW); // Unlock door!
delay(setDelay); // Hold door lock open for given seconds delay(setDelay); // Hold door lock open for given seconds
digitalWrite(relay, HIGH); // Relock door digitalWrite(relay, HIGH); // Relock door
delay(1000); // Hold green LED on for a second delay(1000); // Hold green LED on for a second
} }
///////////////////////////////////////// Access Denied /////////////////////////////////// ///////////////////////////////////////// Access Denied ///////////////////////////////////
void denied() { void denied() {
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_ON); // Turn on red LED digitalWrite(redLed, LED_ON); // Turn on red LED
delay(1000); delay(1000);
} }
///////////////////////////////////////// Get PICC's UID /////////////////////////////////// ///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
int getID() { uint8_t getID() {
// Getting ready for Reading PICCs // Getting ready for Reading PICCs
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0; return 0;
@@ -312,7 +312,7 @@ int getID() {
// I think we should assume every PICC as they have 4 byte UID // I think we should assume every PICC as they have 4 byte UID
// Until we support 7 byte PICCs // Until we support 7 byte PICCs
Serial.println(F("Scanned PICC's UID:")); Serial.println(F("Scanned PICC's UID:"));
for (int i = 0; i < 4; i++) { // for ( uint8_t i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i]; readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX); Serial.print(readCard[i], HEX);
} }
@@ -338,54 +338,54 @@ void ShowReaderDetails() {
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
Serial.println(F("SYSTEM HALTED: Check connections.")); Serial.println(F("SYSTEM HALTED: Check connections."));
// Visualize system is halted // Visualize system is halted
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_ON); // Turn on red LED digitalWrite(redLed, LED_ON); // Turn on red LED
while (true); // do not go further while (true); // do not go further
} }
} }
///////////////////////////////////////// Cycle Leds (Program Mode) /////////////////////////////////// ///////////////////////////////////////// Cycle Leds (Program Mode) ///////////////////////////////////
void cycleLeds() { void cycleLeds() {
digitalWrite(redLed, LED_OFF); // Make sure red LED is off digitalWrite(redLed, LED_OFF); // Make sure red LED is off
digitalWrite(greenLed, LED_ON); // Make sure green LED is on digitalWrite(greenLed, LED_ON); // Make sure green LED is on
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
delay(200); delay(200);
digitalWrite(redLed, LED_OFF); // Make sure red LED is off digitalWrite(redLed, LED_OFF); // Make sure red LED is off
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
digitalWrite(blueLed, LED_ON); // Make sure blue LED is on digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
delay(200); delay(200);
digitalWrite(redLed, LED_ON); // Make sure red LED is on digitalWrite(redLed, LED_ON); // Make sure red LED is on
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
delay(200); delay(200);
} }
//////////////////////////////////////// Normal Mode Led /////////////////////////////////// //////////////////////////////////////// Normal Mode Led ///////////////////////////////////
void normalModeOn () { void normalModeOn () {
digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card digitalWrite(blueLed, LED_ON); // Blue LED ON and ready to read card
digitalWrite(redLed, LED_OFF); // Make sure Red LED is off digitalWrite(redLed, LED_OFF); // Make sure Red LED is off
digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off digitalWrite(greenLed, LED_OFF); // Make sure Green LED is off
digitalWrite(relay, HIGH); // Make sure Door is Locked digitalWrite(relay, HIGH); // Make sure Door is Locked
} }
//////////////////////////////////////// Read an ID from EEPROM ////////////////////////////// //////////////////////////////////////// Read an ID from EEPROM //////////////////////////////
void readID( int number ) { void readID( uint8_t number ) {
int start = (number * 4 ) + 2; // Figure out starting position uint8_t start = (number * 4 ) + 2; // Figure out starting position
for ( int i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes for ( uint8_t i = 0; i < 4; i++ ) { // Loop 4 times to get the 4 Bytes
storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array storedCard[i] = EEPROM.read(start + i); // Assign values read from EEPROM to array
} }
} }
///////////////////////////////////////// Add ID to EEPROM /////////////////////////////////// ///////////////////////////////////////// Add ID to EEPROM ///////////////////////////////////
void writeID( byte a[] ) { void writeID( byte a[] ) {
if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before! if ( !findID( a ) ) { // Before we write to the EEPROM, check to see if we have seen this card before!
int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
int start = ( num * 4 ) + 6; // Figure out where the next slot starts uint8_t start = ( num * 4 ) + 6; // Figure out where the next slot starts
num++; // Increment the counter by one num++; // Increment the counter by one
EEPROM.write( 0, num ); // Write the new count to the counter EEPROM.write( 0, num ); // Write the new count to the counter
for ( int j = 0; j < 4; j++ ) { // Loop 4 times for ( uint8_t j = 0; j < 4; j++ ) { // Loop 4 times
EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position EEPROM.write( start + j, a[j] ); // Write the array values to EEPROM in the right position
} }
successWrite(); successWrite();
Serial.println(F("Succesfully added ID record to EEPROM")); Serial.println(F("Succesfully added ID record to EEPROM"));
@@ -398,26 +398,26 @@ void writeID( byte a[] ) {
///////////////////////////////////////// Remove ID from EEPROM /////////////////////////////////// ///////////////////////////////////////// Remove ID from EEPROM ///////////////////////////////////
void deleteID( byte a[] ) { void deleteID( byte a[] ) {
if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card! if ( !findID( a ) ) { // Before we delete from the EEPROM, check to see if we have this card!
failedWrite(); // If not failedWrite(); // If not
Serial.println(F("Failed! There is something wrong with ID or bad EEPROM")); Serial.println(F("Failed! There is something wrong with ID or bad EEPROM"));
} }
else { else {
int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards uint8_t num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores the number of ID cards
int slot; // Figure out the slot number of the card uint8_t slot; // Figure out the slot number of the card
int start; // = ( num * 4 ) + 6; // Figure out where the next slot starts uint8_t start; // = ( num * 4 ) + 6; // Figure out where the next slot starts
int looping; // The number of times the loop repeats uint8_t looping; // The number of times the loop repeats
int j; uint8_t j;
int count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that stores number of cards
slot = findIDSLOT( a ); // Figure out the slot number of the card to delete slot = findIDSLOT( a ); // Figure out the slot number of the card to delete
start = (slot * 4) + 2; start = (slot * 4) + 2;
looping = ((num - slot) * 4); looping = ((num - slot) * 4);
num--; // Decrement the counter by one num--; // Decrement the counter by one
EEPROM.write( 0, num ); // Write the new count to the counter EEPROM.write( 0, num ); // Write the new count to the counter
for ( j = 0; j < looping; j++ ) { // Loop the card shift times for ( j = 0; j < looping; j++ ) { // Loop the card shift times
EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM EEPROM.write( start + j, EEPROM.read(start + 4 + j)); // Shift the array values to 4 places earlier in the EEPROM
} }
for ( int k = 0; k < 4; k++ ) { // Shifting loop for ( uint8_t k = 0; k < 4; k++ ) { // Shifting loop
EEPROM.write( start + j + k, 0); EEPROM.write( start + j + k, 0);
} }
successDelete(); successDelete();
@@ -427,43 +427,43 @@ void deleteID( byte a[] ) {
///////////////////////////////////////// Check Bytes /////////////////////////////////// ///////////////////////////////////////// Check Bytes ///////////////////////////////////
boolean checkTwo ( byte a[], byte b[] ) { boolean checkTwo ( byte a[], byte b[] ) {
if ( a[0] != NULL ) // Make sure there is something in the array first if ( a[0] != 0 ) // Make sure there is something in the array first
match = true; // Assume they match at first match = true; // Assume they match at first
for ( int k = 0; k < 4; k++ ) { // Loop 4 times for ( uint8_t k = 0; k < 4; k++ ) { // Loop 4 times
if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail
match = false; match = false;
} }
if ( match ) { // Check to see if if match is still true if ( match ) { // Check to see if if match is still true
return true; // Return true return true; // Return true
} }
else { else {
return false; // Return false return false; // Return false
} }
} }
///////////////////////////////////////// Find Slot /////////////////////////////////// ///////////////////////////////////////// Find Slot ///////////////////////////////////
int findIDSLOT( byte find[] ) { uint8_t findIDSLOT( byte find[] ) {
int count = EEPROM.read(0); // Read the first Byte of EEPROM that uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
// is the same as the find[] ID card passed // is the same as the find[] ID card passed
return i; // The slot number of the card return i; // The slot number of the card
break; // Stop looking we found it break; // Stop looking we found it
} }
} }
} }
///////////////////////////////////////// Find ID From EEPROM /////////////////////////////////// ///////////////////////////////////////// Find ID From EEPROM ///////////////////////////////////
boolean findID( byte find[] ) { boolean findID( byte find[] ) {
int count = EEPROM.read(0); // Read the first Byte of EEPROM that uint8_t count = EEPROM.read(0); // Read the first Byte of EEPROM that
for ( int i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry for ( uint8_t i = 1; i <= count; i++ ) { // Loop once for each EEPROM entry
readID(i); // Read an ID from EEPROM, it is stored in storedCard[4] readID(i); // Read an ID from EEPROM, it is stored in storedCard[4]
if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM if ( checkTwo( find, storedCard ) ) { // Check to see if the storedCard read from EEPROM
return true; return true;
break; // Stop looking we found it break; // Stop looking we found it
} }
else { // If not, return false else { // If not, return false
} }
} }
return false; return false;
@@ -472,57 +472,57 @@ boolean findID( byte find[] ) {
///////////////////////////////////////// Write Success to EEPROM /////////////////////////////////// ///////////////////////////////////////// Write Success to EEPROM ///////////////////////////////////
// Flashes the green LED 3 times to indicate a successful write to EEPROM // Flashes the green LED 3 times to indicate a successful write to EEPROM
void successWrite() { void successWrite() {
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_OFF); // Make sure red LED is off digitalWrite(redLed, LED_OFF); // Make sure red LED is off
digitalWrite(greenLed, LED_OFF); // Make sure green LED is on digitalWrite(greenLed, LED_OFF); // Make sure green LED is on
delay(200); delay(200);
digitalWrite(greenLed, LED_ON); // Make sure green LED is on digitalWrite(greenLed, LED_ON); // Make sure green LED is on
delay(200); delay(200);
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
delay(200); delay(200);
digitalWrite(greenLed, LED_ON); // Make sure green LED is on digitalWrite(greenLed, LED_ON); // Make sure green LED is on
delay(200); delay(200);
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
delay(200); delay(200);
digitalWrite(greenLed, LED_ON); // Make sure green LED is on digitalWrite(greenLed, LED_ON); // Make sure green LED is on
delay(200); delay(200);
} }
///////////////////////////////////////// Write Failed to EEPROM /////////////////////////////////// ///////////////////////////////////////// Write Failed to EEPROM ///////////////////////////////////
// Flashes the red LED 3 times to indicate a failed write to EEPROM // Flashes the red LED 3 times to indicate a failed write to EEPROM
void failedWrite() { void failedWrite() {
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_OFF); // Make sure red LED is off digitalWrite(redLed, LED_OFF); // Make sure red LED is off
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
delay(200); delay(200);
digitalWrite(redLed, LED_ON); // Make sure red LED is on digitalWrite(redLed, LED_ON); // Make sure red LED is on
delay(200); delay(200);
digitalWrite(redLed, LED_OFF); // Make sure red LED is off digitalWrite(redLed, LED_OFF); // Make sure red LED is off
delay(200); delay(200);
digitalWrite(redLed, LED_ON); // Make sure red LED is on digitalWrite(redLed, LED_ON); // Make sure red LED is on
delay(200); delay(200);
digitalWrite(redLed, LED_OFF); // Make sure red LED is off digitalWrite(redLed, LED_OFF); // Make sure red LED is off
delay(200); delay(200);
digitalWrite(redLed, LED_ON); // Make sure red LED is on digitalWrite(redLed, LED_ON); // Make sure red LED is on
delay(200); delay(200);
} }
///////////////////////////////////////// Success Remove UID From EEPROM /////////////////////////////////// ///////////////////////////////////////// Success Remove UID From EEPROM ///////////////////////////////////
// Flashes the blue LED 3 times to indicate a success delete to EEPROM // Flashes the blue LED 3 times to indicate a success delete to EEPROM
void successDelete() { void successDelete() {
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
digitalWrite(redLed, LED_OFF); // Make sure red LED is off digitalWrite(redLed, LED_OFF); // Make sure red LED is off
digitalWrite(greenLed, LED_OFF); // Make sure green LED is off digitalWrite(greenLed, LED_OFF); // Make sure green LED is off
delay(200); delay(200);
digitalWrite(blueLed, LED_ON); // Make sure blue LED is on digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
delay(200); delay(200);
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
delay(200); delay(200);
digitalWrite(blueLed, LED_ON); // Make sure blue LED is on digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
delay(200); delay(200);
digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off digitalWrite(blueLed, LED_OFF); // Make sure blue LED is off
delay(200); delay(200);
digitalWrite(blueLed, LED_ON); // Make sure blue LED is on digitalWrite(blueLed, LED_ON); // Make sure blue LED is on
delay(200); delay(200);
} }