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.
Fork of kl25Z_nRF_TX by
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 }
Generated on Wed Jul 20 2022 07:41:29 by
1.7.2
