sends the RFID tag number serially to screen

Dependencies:   ID12RFID mbed

Committer:
lewisjfish
Date:
Fri Jun 12 14:04:03 2015 +0000
Revision:
0:9aa9a6cd3a3d
rfid reader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lewisjfish 0:9aa9a6cd3a3d 1 #include "mbed.h"
lewisjfish 0:9aa9a6cd3a3d 2 #include "ID12RFID.h"
lewisjfish 0:9aa9a6cd3a3d 3
lewisjfish 0:9aa9a6cd3a3d 4
lewisjfish 0:9aa9a6cd3a3d 5 Serial infoout(PTA2,PTA1); //define the serial port, connected to the screen mbed
lewisjfish 0:9aa9a6cd3a3d 6
lewisjfish 0:9aa9a6cd3a3d 7 Serial weatherIn(PTE22,PTE23);
lewisjfish 0:9aa9a6cd3a3d 8
lewisjfish 0:9aa9a6cd3a3d 9
lewisjfish 0:9aa9a6cd3a3d 10 //DigitalOut myled(LED1);
lewisjfish 0:9aa9a6cd3a3d 11 char message[9]; //character array to store the data we send
lewisjfish 0:9aa9a6cd3a3d 12
lewisjfish 0:9aa9a6cd3a3d 13 int tagNumber; //stores the tagnumber read from the RFID reader
lewisjfish 0:9aa9a6cd3a3d 14
lewisjfish 0:9aa9a6cd3a3d 15 char c;
lewisjfish 0:9aa9a6cd3a3d 16 int i;
lewisjfish 0:9aa9a6cd3a3d 17
lewisjfish 0:9aa9a6cd3a3d 18
lewisjfish 0:9aa9a6cd3a3d 19
lewisjfish 0:9aa9a6cd3a3d 20 ID12RFID rfid(PTE1); //Initialise RFID reader and associated functions
lewisjfish 0:9aa9a6cd3a3d 21
lewisjfish 0:9aa9a6cd3a3d 22
lewisjfish 0:9aa9a6cd3a3d 23
lewisjfish 0:9aa9a6cd3a3d 24 int main() {
lewisjfish 0:9aa9a6cd3a3d 25 while(1){
lewisjfish 0:9aa9a6cd3a3d 26
lewisjfish 0:9aa9a6cd3a3d 27 int i=0;
lewisjfish 0:9aa9a6cd3a3d 28
lewisjfish 0:9aa9a6cd3a3d 29 if(rfid.readable()){
lewisjfish 0:9aa9a6cd3a3d 30 //if we can read a tag, get the tagnumber
lewisjfish 0:9aa9a6cd3a3d 31 tagNumber = rfid.read();
lewisjfish 0:9aa9a6cd3a3d 32 sprintf(message,"a%d",tagNumber); //turn the tagnumber into a string, string starts with a to identify string as an RFID tagnumber
lewisjfish 0:9aa9a6cd3a3d 33
lewisjfish 0:9aa9a6cd3a3d 34
lewisjfish 0:9aa9a6cd3a3d 35
lewisjfish 0:9aa9a6cd3a3d 36 for(int n =0; n<9 ; n++){
lewisjfish 0:9aa9a6cd3a3d 37 //send the data to the second mbed(screen) using putc
lewisjfish 0:9aa9a6cd3a3d 38 infoout.putc(message[i]);
lewisjfish 0:9aa9a6cd3a3d 39 i=(i+1)%9; //modulo 9 to ensure only 9 characters are sent
lewisjfish 0:9aa9a6cd3a3d 40
lewisjfish 0:9aa9a6cd3a3d 41 //,waiting 0.05 seconds after each character
lewisjfish 0:9aa9a6cd3a3d 42 wait(0.05);
lewisjfish 0:9aa9a6cd3a3d 43 }
lewisjfish 0:9aa9a6cd3a3d 44
lewisjfish 0:9aa9a6cd3a3d 45 if(i==0){
lewisjfish 0:9aa9a6cd3a3d 46 infoout.putc('A'); //end the message with 'A' to denote the end of an RFID
lewisjfish 0:9aa9a6cd3a3d 47
lewisjfish 0:9aa9a6cd3a3d 48 wait(0.01);
lewisjfish 0:9aa9a6cd3a3d 49 }
lewisjfish 0:9aa9a6cd3a3d 50 }
lewisjfish 0:9aa9a6cd3a3d 51
lewisjfish 0:9aa9a6cd3a3d 52
lewisjfish 0:9aa9a6cd3a3d 53 // if(weatherIn.readable()){
lewisjfish 0:9aa9a6cd3a3d 54
lewisjfish 0:9aa9a6cd3a3d 55 // c=weatherIn.getc();
lewisjfish 0:9aa9a6cd3a3d 56 // infoout.putc(message[i]);
lewisjfish 0:9aa9a6cd3a3d 57 // message[i] = c;
lewisjfish 0:9aa9a6cd3a3d 58 // i=(i+1)%9;
lewisjfish 0:9aa9a6cd3a3d 59
lewisjfish 0:9aa9a6cd3a3d 60 // wait(0.05);
lewisjfish 0:9aa9a6cd3a3d 61 // }
lewisjfish 0:9aa9a6cd3a3d 62
lewisjfish 0:9aa9a6cd3a3d 63
lewisjfish 0:9aa9a6cd3a3d 64
lewisjfish 0:9aa9a6cd3a3d 65
lewisjfish 0:9aa9a6cd3a3d 66
lewisjfish 0:9aa9a6cd3a3d 67 }
lewisjfish 0:9aa9a6cd3a3d 68 }
lewisjfish 0:9aa9a6cd3a3d 69