Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:a34fad3854d2, 2020-04-07 (annotated)
- Committer:
- shanesolomon
- Date:
- Tue Apr 07 20:10:53 2020 +0000
- Revision:
- 1:a34fad3854d2
- Parent:
- 0:ebf3612d4985
RFIDO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ndgohil | 0:ebf3612d4985 | 1 | #include "mbed.h" |
shanesolomon | 1:a34fad3854d2 | 2 | #include "MFRC522.h" |
shanesolomon | 1:a34fad3854d2 | 3 | |
ndgohil | 0:ebf3612d4985 | 4 | // FRDM-K64F (Freescale) Pin for MFRC522 reset |
ndgohil | 0:ebf3612d4985 | 5 | #define MF_RESET PTD0 |
ndgohil | 0:ebf3612d4985 | 6 | #define SERIAL_1 |
ndgohil | 0:ebf3612d4985 | 7 | |
ndgohil | 0:ebf3612d4985 | 8 | DigitalOut LedGreen(LED2); |
shanesolomon | 1:a34fad3854d2 | 9 | PwmOut servo(PTC3); |
shanesolomon | 1:a34fad3854d2 | 10 | Serial pc(USBTX, USBRX); // serial comm on the FRDM board |
ndgohil | 0:ebf3612d4985 | 11 | //MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); |
ndgohil | 0:ebf3612d4985 | 12 | MFRC522 RfChip (PTD2, PTD3, PTD1, PTE25, PTD0); |
ndgohil | 0:ebf3612d4985 | 13 | |
shanesolomon | 1:a34fad3854d2 | 14 | int main(void) |
shanesolomon | 1:a34fad3854d2 | 15 | { |
shanesolomon | 1:a34fad3854d2 | 16 | int fulluid=0; |
ndgohil | 0:ebf3612d4985 | 17 | pc.baud(9600); |
shanesolomon | 1:a34fad3854d2 | 18 | |
shanesolomon | 1:a34fad3854d2 | 19 | printf("Welcome to Project RFIDO, I hope you enjoy your experience!!!...\n\r"); |
shanesolomon | 1:a34fad3854d2 | 20 | |
ndgohil | 0:ebf3612d4985 | 21 | RfChip.PCD_Init(); |
ndgohil | 0:ebf3612d4985 | 22 | |
shanesolomon | 1:a34fad3854d2 | 23 | while (true) |
shanesolomon | 1:a34fad3854d2 | 24 | { |
ndgohil | 0:ebf3612d4985 | 25 | LedGreen = 1; |
ndgohil | 0:ebf3612d4985 | 26 | |
ndgohil | 0:ebf3612d4985 | 27 | // Look for new cards |
ndgohil | 0:ebf3612d4985 | 28 | if ( ! RfChip.PICC_IsNewCardPresent()) |
ndgohil | 0:ebf3612d4985 | 29 | { |
ndgohil | 0:ebf3612d4985 | 30 | wait_ms(200); |
ndgohil | 0:ebf3612d4985 | 31 | continue; |
ndgohil | 0:ebf3612d4985 | 32 | } |
ndgohil | 0:ebf3612d4985 | 33 | |
ndgohil | 0:ebf3612d4985 | 34 | // Select one of the cards |
ndgohil | 0:ebf3612d4985 | 35 | if ( ! RfChip.PICC_ReadCardSerial()) |
ndgohil | 0:ebf3612d4985 | 36 | { |
shanesolomon | 1:a34fad3854d2 | 37 | |
ndgohil | 0:ebf3612d4985 | 38 | wait_ms(200); |
ndgohil | 0:ebf3612d4985 | 39 | continue; |
ndgohil | 0:ebf3612d4985 | 40 | } |
ndgohil | 0:ebf3612d4985 | 41 | LedGreen = 0; |
shanesolomon | 1:a34fad3854d2 | 42 | int a=0; int b=0; int c=0;int d=0; int e=0; int f=0;int g=0; int h=0; |
shanesolomon | 1:a34fad3854d2 | 43 | |
ndgohil | 0:ebf3612d4985 | 44 | // Print Card UID |
ndgohil | 0:ebf3612d4985 | 45 | printf("Card UID:"); |
shanesolomon | 1:a34fad3854d2 | 46 | //blue.printf("Card UID:"); |
ndgohil | 0:ebf3612d4985 | 47 | for (uint8_t i = 0; i < RfChip.uid.size; i++) |
ndgohil | 0:ebf3612d4985 | 48 | { |
ndgohil | 0:ebf3612d4985 | 49 | printf(" %X02 ", RfChip.uid.uidByte[i]); |
shanesolomon | 1:a34fad3854d2 | 50 | |
shanesolomon | 1:a34fad3854d2 | 51 | //blue.printf(" %X02 ", RfChip.uid.uidByte[i]); |
ndgohil | 0:ebf3612d4985 | 52 | a = RfChip.uid.uidByte[0]; |
shanesolomon | 1:a34fad3854d2 | 53 | b = RfChip.uid.uidByte[1]; |
shanesolomon | 1:a34fad3854d2 | 54 | c = RfChip.uid.uidByte[2]; |
shanesolomon | 1:a34fad3854d2 | 55 | d = RfChip.uid.uidByte[3]; |
shanesolomon | 1:a34fad3854d2 | 56 | e = RfChip.uid.uidByte[4]; |
shanesolomon | 1:a34fad3854d2 | 57 | f = RfChip.uid.uidByte[5]; |
shanesolomon | 1:a34fad3854d2 | 58 | g = RfChip.uid.uidByte[6]; |
shanesolomon | 1:a34fad3854d2 | 59 | h = RfChip.uid.uidByte[7]; |
shanesolomon | 1:a34fad3854d2 | 60 | |
ndgohil | 0:ebf3612d4985 | 61 | } |
shanesolomon | 1:a34fad3854d2 | 62 | |
shanesolomon | 1:a34fad3854d2 | 63 | fulluid = a+b+c+d+e+f+g+h; |
shanesolomon | 1:a34fad3854d2 | 64 | printf("\n\r"); |
shanesolomon | 1:a34fad3854d2 | 65 | |
ndgohil | 0:ebf3612d4985 | 66 | |
shanesolomon | 1:a34fad3854d2 | 67 | |
ndgohil | 0:ebf3612d4985 | 68 | //Print Card Type |
shanesolomon | 1:a34fad3854d2 | 69 | if(a==153) |
ndgohil | 0:ebf3612d4985 | 70 | { |
shanesolomon | 1:a34fad3854d2 | 71 | printf("\r\nWelcome Fido, Enjoy your tasty feast!"); |
shanesolomon | 1:a34fad3854d2 | 72 | |
ndgohil | 0:ebf3612d4985 | 73 | } |
shanesolomon | 1:a34fad3854d2 | 74 | |
ndgohil | 0:ebf3612d4985 | 75 | else |
ndgohil | 0:ebf3612d4985 | 76 | { |
shanesolomon | 1:a34fad3854d2 | 77 | printf("\r\nUnrecognized tag"); |
shanesolomon | 1:a34fad3854d2 | 78 | printf("\r\nSCRAM YOU FILTHY ANIMAL!!!"); |
ndgohil | 0:ebf3612d4985 | 79 | } |
shanesolomon | 1:a34fad3854d2 | 80 | |
ndgohil | 0:ebf3612d4985 | 81 | printf("\n\r"); |
shanesolomon | 1:a34fad3854d2 | 82 | |
shanesolomon | 1:a34fad3854d2 | 83 | |
shanesolomon | 1:a34fad3854d2 | 84 | //blue.printf("\n\r"); |
ndgohil | 0:ebf3612d4985 | 85 | |
ndgohil | 0:ebf3612d4985 | 86 | // Print RFID Card type |
ndgohil | 0:ebf3612d4985 | 87 | uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); |
ndgohil | 0:ebf3612d4985 | 88 | printf("PICC Type: %s \n\n\r\r", RfChip.PICC_GetTypeName(piccType)); |
ndgohil | 0:ebf3612d4985 | 89 | |
ndgohil | 0:ebf3612d4985 | 90 | wait_ms(200); |
ndgohil | 0:ebf3612d4985 | 91 | |
shanesolomon | 1:a34fad3854d2 | 92 | while (fulluid==721) |
shanesolomon | 1:a34fad3854d2 | 93 | { |
shanesolomon | 1:a34fad3854d2 | 94 | |
shanesolomon | 1:a34fad3854d2 | 95 | servo.period(0.020f); |
shanesolomon | 1:a34fad3854d2 | 96 | servo.pulsewidth_ms(2); // servo position determined by a pulsewidth between 1-2ms |
shanesolomon | 1:a34fad3854d2 | 97 | wait(15); |
shanesolomon | 1:a34fad3854d2 | 98 | servo.pulsewidth_ms(1.5f); |
shanesolomon | 1:a34fad3854d2 | 99 | fulluid=0; |
shanesolomon | 1:a34fad3854d2 | 100 | } |
shanesolomon | 1:a34fad3854d2 | 101 | } |
shanesolomon | 1:a34fad3854d2 | 102 | } |
shanesolomon | 1:a34fad3854d2 | 103 | |
shanesolomon | 1:a34fad3854d2 | 104 | |
ndgohil | 0:ebf3612d4985 | 105 |