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: ISR_Mini-explorer RF24 mbed
main.cpp
00001 #include "mbed.h" 00002 #include "robot.h" // Inicializa o robô. Este include deverá ser usado em todos os main.cpp! 00003 //#include "nRF24L01P.h" 00004 #include <RF24.h> 00005 00006 #define TRANSFER_SIZE 1 00007 00008 //nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTC13, PTC12, PTA13); 00009 RF24 radio(PTD2, PTD3, PTD1, PTC12 ,PTC13); 00010 00011 00012 void config_init_nrf2() 00013 { 00014 int resultado; 00015 resultado = radio.begin(); 00016 00017 pc.printf( "Begin=%d\r\n", resultado ); 00018 radio.setDataRate(RF24_1MBPS); 00019 radio.setCRCLength(RF24_CRC_8); 00020 radio.setPayloadSize(1); 00021 radio.setChannel(101); 00022 radio.setAutoAck(true); 00023 radio.printDetails(); 00024 00025 radio.openWritingPipe(0x314e6f6465); 00026 radio.openReadingPipe(1,0x324e6f6465 ); 00027 00028 radio.startListening(); 00029 } 00030 00031 int main() 00032 { 00033 char txData, rxData; 00034 00035 00036 initRobot(); 00037 pc.baud(9600); 00038 config_init_nrf2(); // Should be after pc.baud() 00039 00040 pc.printf( "Robot A\r\n" ); 00041 00042 00043 // Desliga os LEDs. 00044 q_led_red_fro = 1; //Led Red Front 00045 q_led_gre_fro = 1; //Led Green Front 00046 q_led_blu_fro = 1; //Led Blue Front 00047 q_led_red_rea = 1; //Led Red Rear 00048 q_led_gre_rea = 1; //Led Green Rear 00049 q_led_blu_rea = 1; //Led Blue Rear 00050 00051 while (1) { 00052 00053 // If we've received anything over the host serial link... 00054 if ( pc.readable() ) { 00055 00056 // ...add it to the transmit buffer 00057 txData = pc.getc(); 00058 00059 // Send the transmitbuffer via the nRF24L01+ 00060 //pc.printf( "Vou enviar: %c\r\n",txData); 00061 radio.stopListening(); 00062 radio.write( &txData, sizeof(txData) ); 00063 radio.startListening(); 00064 00065 00066 // Toggle LED1 (to help debug Host -> nRF24L01+ communication) 00067 q_led_red_fro = !q_led_red_fro; 00068 } 00069 00070 // If we've received anything in the nRF24L01+... 00071 if (radio.available() ) { 00072 00073 // ...read the data into the receive buffer 00074 //my_nrf24l01p.read( NRF24L01P_PIPE_P0, &rxData, sizeof( rxData ) ); 00075 radio.read( &rxData, sizeof(rxData) ); 00076 00077 00078 00079 pc.putc( rxData ); 00080 00081 00082 // Toggle LED2 (to help debug nRF24L01+ -> Host communication) 00083 q_led_red_rea = !q_led_red_rea; 00084 } 00085 } 00086 }
Generated on Mon Jul 25 2022 21:23:58 by
1.7.2