Paul Martin
/
LACCgame_rx
wireless educational game for use with Python3 code
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "nRF24L01P.h" 00003 00004 Serial pc(USBTX, USBRX); // tx, rx 00005 nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq 00006 00007 DigitalOut led1(LED1); 00008 DigitalOut led2(LED2); 00009 DigitalOut led3(LED3); 00010 DigitalOut led4(LED4); 00011 00012 int main() { 00013 00014 // set up PC comm. 00015 pc.baud(115200); 00016 00017 // set up wireless transfer size 00018 #define TRANSFER_SIZE 3 00019 00020 char rxData[TRANSFER_SIZE]; 00021 int rxDataCnt = 0; 00022 00023 // initialize wireless comm. 00024 my_nrf24l01p.powerUp(); 00025 my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); 00026 my_nrf24l01p.setReceiveMode(); 00027 my_nrf24l01p.enable(); 00028 my_nrf24l01p.setAirDataRate(2000); 00029 // set wireless RX 00030 my_nrf24l01p.setRxAddress(0xABCDABCDABCDABCD); 00031 00032 // Display the (default) setup of the nRF24L01+ chip 00033 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00034 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00035 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00036 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00037 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); 00038 00039 while (1) { 00040 led1 = 1; 00041 00042 // If we've received anything in the nRF24L01+... 00043 if ( my_nrf24l01p.readable() ) { 00044 00045 // ...read the data into the receive buffer 00046 rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); 00047 00048 // Display the receive buffer contents via the host serial link 00049 for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { 00050 pc.printf( "%d,", rxData[i] ); 00051 } 00052 pc.printf("\n\r"); 00053 00054 // Toggle LED2 (to help debug nRF24L01+ -> Host communication) 00055 led2 = !led2; 00056 } 00057 } 00058 }
Generated on Mon Jul 18 2022 21:50:05 by 1.7.2