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.
Diff: main.cpp
- Revision:
- 7:43bb8be87709
- Parent:
- 6:c3d9f6a28df6
--- a/main.cpp Mon Dec 10 13:51:23 2018 +0000 +++ b/main.cpp Mon Dec 10 13:58:55 2018 +0000 @@ -15,6 +15,18 @@ int led = 0; bool ackknowledged = true; +void setLed(int i) { + printf("Setting led to %d", i); + cs = 0; + spi.write(0x46); + spi.write(0x09); + + int mask = 1; + int writeValue = 255; + writeValue ^= mask << i; + spi.write(writeValue); + cs = 1; +} void init() { cs = 0; @@ -41,19 +53,10 @@ my_nrf24l01p.setReceiveMode(); my_nrf24l01p.enable(); + + setLed(led); } -void setLed(int i) { - cs = 0; - spi.write(0x46); - spi.write(0x09); - - int mask = 1; - int writeValue = 255; - writeValue ^= mask << i; - spi.write(writeValue); - cs = 1; -} void readNRF() { // If we've received anything in the nRF24L01+... @@ -61,16 +64,15 @@ // ...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 - printf("Received %d for: %d\n\r", rxData[0], rxData[1]); if (rxData[0] == 0) { + printf("Received request for %d", rxData[1]); txData[0] = 1; txData[1] = rxData[1]; my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, TRANSFER_SIZE ); } if (rxData[0] == 1) { + printf("Received acknowledgment for %d", rxData[1]); ackknowledged = true; setLed(rxData[1]); } @@ -114,12 +116,8 @@ int main() { cs = 1; - printf("Initializing. \n\r"); init(); - printf("Setting Led. \n\r"); - // Select the device by seting chip select low - printf("Starting \n\r"); while (true) { readButton(); readNRF();