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.
Dependencies: BSP_DISCO_L476VG LCD_DISCO_L476VG mbed nRF24L01P
Fork of Final_projectnew by
Revision 5:8d2188479eec, committed 2018-04-20
- Comitter:
- jblackann
- Date:
- Fri Apr 20 20:10:03 2018 +0000
- Parent:
- 4:dcee65c6cebf
- Commit message:
- Added Channel code function and help menu
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Apr 17 21:33:05 2018 +0000
+++ b/main.cpp Fri Apr 20 20:10:03 2018 +0000
@@ -10,6 +10,43 @@
DigitalOut myled2(LED2);
LCD_DISCO_L476VG lcd;
+void channelChangeMode (void)
+{
+ char stayInWhile = 1;
+ char receivedChannelCharacter;
+ int rf_channel = 2400;
+ pc.printf("Channel menu\n\r");
+ pc.printf("select channel\n\r");
+ while(stayInWhile)
+ {
+ pc.printf("waiting for Channel\n\r");
+ if ( pc.readable() )
+ {
+
+ receivedChannelCharacter = pc.getc();
+
+ if (receivedChannelCharacter >= '1' && receivedChannelCharacter <= '9') // if received 0 through 9 load transmit buffer
+k {
+ pc.printf("received valid number\n\r");
+ receivedChannelCharacter = receivedChannelCharacter - 0x30;
+ rf_channel = rf_channel + receivedChannelCharacter;
+ pc.printf("new channel, %d\n\r", rf_channel);
+ my_nrf24l01p.setRfFrequency(rf_channel);
+ wait(1);
+ pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
+ stayInWhile = 0;
+ }
+ else
+ {
+ pc.printf(" invalid number\n\r");
+ }
+ }
+ wait(1);
+ }
+ pc.printf("exiting Channel change mode\n\r");
+
+}
+
int main() {
// The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
@@ -20,6 +57,8 @@
char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
int txDataCnt = 0;
int rxDataCnt = 0;
+ char receivedTerminalCharacter;
+
uint32_t temp = 0;
uint8_t stemp[7] = {0};
//uint8_t title[] = " DISCOVERY STM32L476";
@@ -51,21 +90,44 @@
// If we've received anything over the host serial link...
if ( pc.readable() ) {
+
+ receivedTerminalCharacter = pc.getc();
- // ...add it to the transmit buffer
- txData[txDataCnt++] = pc.getc();}
+ if (receivedTerminalCharacter >= '0' && receivedTerminalCharacter <= '9') // if received 0 through 9 load transmit buffer
+ {
+ pc.printf("Loading TX buffer");
+ // ...add it to the transmit buffer
+ txData[txDataCnt++] = pc.getc();
+
- // If the transmit buffer is full
- if ( txDataCnt >= sizeof( txData ) ) {
+ // If the transmit buffer is full
+ if ( txDataCnt >= sizeof( txData ) ) {
+
+ // Send the transmitbuffer via the nRF24L01+
+ my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
+
+ txDataCnt = 0;
+
- // Send the transmitbuffer via the nRF24L01+
- my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
-
- txDataCnt = 0;
+ // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
+ myled1 = !myled1;
+ }
+ }
-
- // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
- myled1 = !myled1;
+ else if (receivedTerminalCharacter == 'h')
+ {
+ pc.printf("Radio help menu\n\r");
+ pc.printf("Press c for channel: \n\r");
+ pc.printf("Press t for TX Power: \n\r");
+ pc.printf("Press d for datarate: \n\r");
+ }
+ else if (receivedTerminalCharacter == 'c')
+ {
+
+ channelChangeMode();
+
+ }
+
}
// If we've received anything in the nRF24L01+...
