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
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2019 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 */ 00005 00006 #include "mbed.h" 00007 //#include "platform/mbed_thread.h" 00008 #include "hcsr04.h" 00009 00010 DigitalOut myled(LED1); 00011 Serial pc(USBTX,USBRX); 00012 HCSR04 usensor(D8, D9); 00013 unsigned int dist; 00014 DigitalOut GREEN(D7); 00015 DigitalOut BLUE(LED3); 00016 Timer dt; 00017 00018 00019 #include "MFRC522.h" 00020 // FRDM-K64F (Freescale) Pin for MFRC522 reset 00021 #define MF_RESET PTD0 00022 #define SERIAL_1 00023 00024 DigitalOut LedGreen(LED2); 00025 00026 //Serial connection to PC for output 00027 //Serial pc(PTC17, PTC16); // serial comm on the FRDM board 00028 00029 //wireless bluetooth connection to Android Device for output 00030 Serial blue(PTC15, PTC14); 00031 00032 00033 //MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); 00034 MFRC522 RfChip (PTD2, PTD3, PTD1, PTE25, PTD0); 00035 00036 int counter1 = 0; 00037 int counter2 = 0; 00038 00039 00040 00041 // Blinking rate in milliseconds 00042 //#define BLINKING_RATE_MS 500 00043 00044 00045 int main() 00046 { 00047 // Initialise the digital pin LED1 as an output 00048 DigitalOut led(LED1); 00049 00050 /*while (true) { 00051 led = !led; 00052 //thread_sleep_for(BLINKING_RATE_MS); 00053 }*/ 00054 BLUE=1; 00055 pc.baud(9600); 00056 dt.start(); 00057 while(1) { 00058 usensor.start(); 00059 wait_ms(500); 00060 dist=usensor.get_dist_cm(); 00061 pc.printf("\n\r cm:%ld",dist); 00062 00063 printf("Welcome to RFID Tag Reader Using FRDM K64F...\n\r"); 00064 blue.printf("Welcome to RFID Tag Reader Uing FRDM K64F...\n\r"); 00065 printf("Bluetooth Enable\r\n"); 00066 blue.printf("Bluetooth Enable\r\n"); 00067 RfChip.PCD_Init(); 00068 00069 00070 LedGreen = 1; 00071 00072 // Look for new cards 00073 if ( ! RfChip.PICC_IsNewCardPresent()) 00074 { 00075 if (dist>20) 00076 { 00077 GREEN = !GREEN; 00078 } 00079 else 00080 { 00081 BLUE=0; 00082 continue; 00083 } 00084 } 00085 00086 // Select one of the cards 00087 if ( ! RfChip.PICC_ReadCardSerial()) 00088 { 00089 if (dist>20) 00090 { 00091 GREEN = !GREEN; 00092 } 00093 else 00094 { 00095 BLUE=0; 00096 continue; 00097 } 00098 } 00099 LedGreen = 0; 00100 int a=0; 00101 00102 // Print Card UID 00103 printf("Card UID:"); 00104 blue.printf("Card UID:"); 00105 for (uint8_t i = 0; i < RfChip.uid.size; i++) 00106 { 00107 printf(" %X02 ", RfChip.uid.uidByte[i]); 00108 blue.printf(" %X02 ", RfChip.uid.uidByte[i]); 00109 a = RfChip.uid.uidByte[0]; 00110 } 00111 printf("%d",a); 00112 00113 //Print Card Type 00114 if(a==73) 00115 { 00116 if(counter1 == 0){ 00117 printf("\r\nMilk is in the fridge"); 00118 blue.printf("\r\nWhite Card"); 00119 counter1 = 1; 00120 } 00121 else if(counter1 == 1){ 00122 printf("\r\nMilk is out of the fridge"); 00123 counter1 = 0; 00124 } 00125 } 00126 00127 if(a==207) 00128 { 00129 if (counter2 == 0) 00130 { 00131 printf("\r\nBeer is in the fridge"); 00132 blue.printf("\r\nBlue Keychain"); 00133 counter2 = 1; 00134 } 00135 else if (counter2 == 1){ 00136 printf("\r\nBeer is out of the fridge"); 00137 counter2 = 0; 00138 } 00139 } 00140 //wait(1); 00141 printf("\n\r"); 00142 blue.printf("\n\r"); 00143 00144 printf("\r\nParcel taken"); 00145 blue.printf("\r\nParcel taken"); 00146 00147 printf("\n\r"); 00148 blue.printf("\n\r"); 00149 00150 // Print RFID Card type 00151 uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); 00152 printf("PICC Type: %s \n\n\r\r", RfChip.PICC_GetTypeName(piccType)); 00153 blue.printf("PICC Type: %s \n\n\r\r", RfChip.PICC_GetTypeName(piccType)); 00154 break; 00155 } 00156 00157 blue.baud(9600); 00158 pc.baud(9600); 00159 } 00160 00161 00162 00163
Generated on Wed Jul 27 2022 08:38:07 by
1.7.2