This is a RFID based attendance system. The current program is only for two users but can be easily scaled for more users. Apart from FRDM-K64F board, we have MFRC522, Nokia 5110 LCD and SD card as external hardware. Each time a legitimate card is flashed the name of the person will be displayed on the LCD and his information will be stored in SD card if it's already not there. I have used existing libraries for all the harware. Here is the list. MFRC522 - By Martin Olejar SDFileSystem - By Andrew Lindsay NOKIA_5110 - By Chris Yan.
Dependencies: MFRC522 NOKIA_5110 SDFileSystem mbed
Fork of FTF2014_lab4 by
Diff: main.cpp
- Revision:
- 5:9f7e1200059e
- Parent:
- 4:6ba6c4be9dde
- Child:
- 6:bc2ca526022f
--- a/main.cpp Sat May 02 19:29:57 2015 +0000 +++ b/main.cpp Sat May 02 20:52:44 2015 +0000 @@ -31,9 +31,9 @@ char abhishektemp[17]; int usercount=0; -int found=0; -int flag=0; //checks if the card scanner is run for the first time -int m=0; +//int found=0; +int flagSam=0; +int flagAbi=0; //checks if the card scanner is run for the first time int main() @@ -63,7 +63,8 @@ // Look for new cards if ( ! RfChip.PICC_IsNewCardPresent()) { - wait_ms(200); + RfChip.PCD_Init(); + wait_ms(300); continue; } @@ -86,123 +87,74 @@ user[i]=RfChip.uid.uidByte[i]; } printf("\n"); - - if(flag) - { found=0; - for(uint8_t i = 0; i < usercount; i++) - { - for (uint8_t j = 0; j < RfChip.uid.size; j++) - { - if(userlist[i][j]==user[j]) - { - found++; - printf("Found=%d\n",found); - } - //set some flag to not write name to sd card or array - } - } - if(found==9) - { - printf("user already present"); + - } - else - { - //userlist[i][j]==user[i]; - for (uint8_t j = 0; j < RfChip.uid.size; j++) - { - userlist[usercount][j]=user[j]; - } - - usercount++; - printf("\n user added"); - } - } - else - { - printf("inside the else\n"); - for (uint8_t i = 0; i < RfChip.uid.size; i++) //make it size of user - { - userlist[0][i]=user[i]; - printf("%i %X02 \n",i, userlist[0][i]); - //set some flag to not write name to sd card or array - } - usercount++; - printf("First user added\n"); - flag=1; - } - - - - + sprintf(abhishektemp,"%X02%X02%X02%X02",user[0],user[1],user[2],user[3]); - printf("Abitemp is %s",abhishektemp); - for(uint8_t i = 0; i < RfChip.uid.size; i++) - { - abhishektemp[i]=user[i]; + if(strcmp(abhishektemp, abhishek)==0) + { + printf("\n found abhishek\n"); + if (flagAbi==1) + { + printf("Already logged in!\n"); + lcd.printString("Abichek",0,0); + } + else if (flagAbi==0) + { + printf("\nWriting data to the sd card \n"); + fp = fopen("/sd/attendance.txt", "rw"); + if (fp == NULL) + { + pc.printf("Unable to write the file \n"); + } + else + { + while(!feof(fp)) {}; + fprintf(fp, "\nAbhishek PRESENT \n"); + fclose(fp); + } + flagAbi=1; + lcd.printString("ABHISHEK",0,0); + } + } + else if(strcmp(abhishektemp,sam)==0) + { + printf("\n found Sam\n"); + if (flagSam==1) + { + printf("Already logged in!\n"); + lcd.printString("Sam",0,0); + } + else if (flagSam==0) + { + printf("\nWriting data to the sd card \n"); + fp = fopen("/sd/attendance.txt", "w"); + if (fp == NULL) + { + pc.printf("Unable to write the file \n"); + } + else + { + while(!feof(fp)) {}; + fprintf(fp, "\nSAM PRESENT \n"); + fclose(fp); + } + flagSam=1; + printf("FlagSam=%i\n",flagSam); + lcd.printString("Sam",0,0); + + } - } -if(strcmp(abhishektemp, abhishek)==0) -{ - printf("\n found abhishek"); -lcd.printString("ABHISHEK",0,0); -continue; -} -else if(strcmp(abhishektemp,sam)==0) -{ -printf("\n found sam"); -lcd.printString("SAM",0,0); -continue; -} -else -{ - continue; -} -} - + printf("Just after continue\n"); + } - // Print Card type - uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); - printf("\n PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); - wait_ms(100); - + else + { + continue; + } - printf("\nWriting data to the sd card \n"); - fp = fopen("/sd/attendance.txt", "w"); - if (fp == NULL) - { - pc.printf("Unable to write the file \n"); - } - else - { - fprintf(fp, "\n ATTENDANCE RECORD \n ABHISHEK PRESENT \n"); - for(uint8_t i = 0; i < usercount; i++) - { - for (uint8_t j = 0; j < RfChip.uid.size; j++) - { - /* if(userlist[i][j]==sam[j]) - { - - fprintf(fp, "\n SAM PRESENT \n"); - - } - else if(userlist[i][j]==abhishek[j]) - { - fprintf(fp, "\n ABHISHEK PRESENT \n"); - - } */ - - // std::fputc(userlist[i][j],fp); - fprintf(fp,"%s",userlist[i][j]); - // uint8_t fwrite(userlist[i][j],100,sizeof(userlist[i][j]),fp); - } - } - fclose(fp); - pc.printf("File successfully written! \n"); - } - printf("\nReading data from the SD card. \n"); fp = fopen("/sd/attendance.txt", "r"); if (fp != NULL) @@ -212,4 +164,4 @@ fclose(fp); } } - +} \ No newline at end of file