KenYEAH! 2k15 / Mbed 2 deprecated sender

Dependencies:   ID12RFID NRF2401P mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ID12RFID.h"
00003 #include "NRF2401P.h"
00004 #include "nRF24l01.h"
00005 
00006 Serial infoout(PTA2,PTA1); //define the serial port, connected to the screen mbed
00007 
00008 Serial weatherIn(PTE22,PTE23);
00009 
00010 
00011 //DigitalOut myled(LED1);
00012 char message[9]; //character array to store the data we send
00013 
00014 int tagNumber; //stores the tagnumber read from the RFID reader
00015 
00016 char c;
00017 int i;
00018 
00019 
00020 
00021 ID12RFID rfid(PTE1); //Initialise RFID reader and associated functions
00022 
00023 
00024 
00025 int main() {
00026     
00027      long long addr1=0xAB01CD; // setup address - any 5 byte number - same as TX
00028      int channel =0x10;  // [0-126] setup channel, must be same as TX
00029      bool txOK;
00030      char msg[32];
00031      char ackData[32];
00032      char len;
00033      
00034      // Setup 
00035      NRF2401P nrf1(PTD2,PTD3, PTD1,PTD5,PTD0); //mosi, miso, sclk, csn, ce)
00036      nrf1.quickRxSetup(channel, addr1); // sets nrf24l01+ as  receiver, using pipe 1
00037      printf("Set up complete!\n\r");
00038      
00039      // set ack data
00040      sprintf(ackData,"Acknowledge data");
00041      printf("Ack data set.\n\r");
00042     
00043     while(1){
00044         
00045 // receive
00046          while (! nrf1.isRxData()); // note this blocks until RX data
00047           
00048          len= nrf1.getRxData(msg); // gets the message, len is length of msg
00049          msg[len] = 0;
00050          printf("%s",msg);
00051          nrf1.acknowledgeData(ackData, strlen(ackData),1); // ack for pipe 1
00052          
00053         for(int n =0; n<sizeof(msg) ; n++){
00054             //send the data to the second mbed(screen) using putc
00055             infoout.putc(msg[n]);
00056             //,waiting 0.05 seconds after each character
00057             wait(0.05);
00058             }
00059 //        
00060         int i=0;
00061 /*
00062         if(rfid.readable()){
00063                //if we can read a tag, get the tagnumber
00064                tagNumber = rfid.read();
00065               sprintf(message,"a%d",tagNumber); //turn the tagnumber into a string, string starts with a to identify string as an RFID tagnumber
00066               
00067                
00068             
00069             for(int n =0; n<9 ; n++){
00070             //send the data to the second mbed(screen) using putc
00071             infoout.putc(message[i]);
00072             i=(i+1)%9; //modulo 9 to ensure only 9 characters are sent
00073             
00074             //,waiting 0.05 seconds after each character
00075             wait(0.05);
00076             }
00077             
00078             if(i==0){
00079             infoout.putc('A'); //end the message with 'A' to denote the end of an RFID
00080             
00081             wait(0.01);
00082             }
00083         }
00084                
00085         
00086         if(weatherIn.readable()){
00087        
00088                 c=weatherIn.getc();
00089                 infoout.putc(message[i]);
00090                 message[i] = c;
00091                 i=(i+1)%9;
00092                 
00093                 wait(0.05);
00094         }             
00095             
00096 
00097             
00098             
00099        */ 
00100     }
00101         
00102                  
00103 }
00104