Janhavi Kulkarni / Mbed 2 deprecated kl25Z_nRF_TX_WSN

Dependencies:   mbed nRF24L01P

Fork of kl25Z_nRF_TX by Ganesh Gore

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Transmitter.cpp Source File

Transmitter.cpp

00001 #include "mbed.h"
00002 #include "nRF24L01P.h"
00003  
00004 Serial pc(USBTX, USBRX); // tx, rx
00005  
00006 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4);    // mosi, miso, sck, csn, ce, irq
00007 DigitalOut RedLED(LED1);
00008 AnalogIn ldr(A1);
00009 AnalogIn pot(A0);
00010  
00011 int main()
00012 {
00013     char count[2];
00014     char TxDataCnt;
00015     char temp;
00016  
00017     my_nrf24l01p.powerUp();
00018     my_nrf24l01p.setRfFrequency(2410);
00019  
00020     // Display the (default) setup of the nRF24L01+ chip
00021     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
00022     pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
00023     pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
00024     pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
00025     pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
00026  
00027     pc.printf( "Wirelesss sensor network \r\n");
00028         
00029     TxDataCnt = 2;
00030     my_nrf24l01p.setTransferSize(TxDataCnt);
00031  
00032     my_nrf24l01p.enable();
00033     
00034     char ldr_val, pot_val;
00035     
00036     while (1) {
00037         
00038         //adjusting data to 0-255 with char data type
00039         ldr_val = 255*(ldr.read());
00040         pot_val = 255*(pot.read());
00041         
00042         count[0] = ldr_val;
00043         count[1] = pot_val;
00044         
00045         // Send the Transmit buffer via the nRF24L01+
00046         temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt );
00047  
00048         pc.printf( "Sending %d bytes; LDR=%d, POT=%d\r\n",temp,count[0], count[1]);
00049  
00050         // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
00051         RedLED = !RedLED;
00052           
00053         wait(1);
00054     }
00055 }