Paul Martin
/
LACCgame_rx
wireless educational game for use with Python3 code
Revision 0:782928220968, committed 2015-07-09
- Comitter:
- caeng
- Date:
- Thu Jul 09 00:32:26 2015 +0000
- Commit message:
- LACC quasar wireless game
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jul 09 00:32:26 2015 +0000 @@ -0,0 +1,58 @@ +#include "mbed.h" +#include "nRF24L01P.h" + +Serial pc(USBTX, USBRX); // tx, rx +nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10); // mosi, miso, sck, csn, ce, irq + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +int main() { + + // set up PC comm. + pc.baud(115200); + + // set up wireless transfer size + #define TRANSFER_SIZE 3 + + char rxData[TRANSFER_SIZE]; + int rxDataCnt = 0; + + // initialize wireless comm. + my_nrf24l01p.powerUp(); + my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); + my_nrf24l01p.setReceiveMode(); + my_nrf24l01p.enable(); + my_nrf24l01p.setAirDataRate(2000); + // set wireless RX + my_nrf24l01p.setRxAddress(0xABCDABCDABCDABCD); + + // Display the (default) setup of the nRF24L01+ chip + pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); + pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); + pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); + pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); + pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); + + while (1) { + led1 = 1; + + // If we've received anything in the nRF24L01+... + if ( my_nrf24l01p.readable() ) { + + // ...read the data into the receive buffer + rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); + + // Display the receive buffer contents via the host serial link + for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { + pc.printf( "%d,", rxData[i] ); + } + pc.printf("\n\r"); + + // Toggle LED2 (to help debug nRF24L01+ -> Host communication) + led2 = !led2; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jul 09 00:32:26 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nRF24L01P.lib Thu Jul 09 00:32:26 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Owen/code/nRF24L01P/#8ae48233b4e4