Eduvance IoTLabs / Mbed 2 deprecated WirelessSensorNetwork_TX

Dependencies:   mbed nRF24L01P

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001  #include "mbed.h"
00002 #include "nRF24L01P.h"
00003 
00004 Serial pc(USBTX, USBRX); 
00005 
00006 //NRF connections to mbed
00007 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4);    // mosi, miso, sck, csn, ce, irq
00008 DigitalOut RedLED(LED1);
00009 
00010 AnalogIn pot(PTB0);
00011 AnalogIn ldr(PTB1);
00012 
00013 int main()
00014 {
00015     
00016     float potval;
00017     char potc;
00018     float ldrval;
00019     char ldrc;
00020     
00021     char count[2];
00022     char TxDataCnt;
00023     char temp;
00024     int k = 255; 
00025     //waking up NRF
00026     my_nrf24l01p.powerUp();
00027     
00028     //setting frequency of NRF
00029     my_nrf24l01p.setRfFrequency(2410); 
00030 
00031     //display default settings of NRF
00032     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
00033     pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
00034     pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
00035     pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
00036     pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
00037 
00038     pc.printf( "Simple Transmitter \r\n");
00039     
00040     TxDataCnt = 2;
00041     
00042     //set packet size of NRF
00043     my_nrf24l01p.setTransferSize(TxDataCnt);
00044     
00045     //enabling radio of NRF
00046     my_nrf24l01p.enable();
00047     
00048     //sending test count value
00049     //count[0] = 0x01;
00050     //count[1] = 0x01;
00051 
00052     while (1) {
00053         
00054         potval = pot.read();
00055         potc = potval*k;
00056         ldrval = ldr.read();
00057         ldrc = ldrval*k;
00058         
00059         count[0] = potc;
00060         count[1] = ldrc;
00061 
00062         //Send the Transmit buffer via the nRF24L01+
00063         temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt );
00064         
00065         //print how many bytes sent
00066         pc.printf( "Sending %d -pot - %d ldr - %d\r\n",temp,count[0],count[1]);
00067 
00068         //toggle debug led
00069         RedLED = !RedLED;
00070             
00071         //update count
00072         //count[0]++;
00073         
00074         wait(0.5);
00075     }
00076 }