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.
main.cpp
- Committer:
- hyunsungkim
- Date:
- 2018-11-03
- Revision:
- 3:690740ab3394
- Parent:
- 2:4d2d1b988c14
- Child:
- 4:ae81aeeed069
File content as of revision 3:690740ab3394:
#include "mbed.h"
#include <RF24Network.h>
#include <RF24.h>
#include "beep.h"
/* Set */
#define NODE_ADDR 00
#define nrf_CE D2
#define nrf_CSN A3
#define spi_SCK D13
#define spi_MOSI D11
#define spi_MISO D12
RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
RF24Network network(radio);
Serial pc(USBTX, USBRX);
Serial lidar(D1, D0);
PwmOut motor_RA(D9);
PwmOut motor_RB(D10);
PwmOut motor_LA(D3);
PwmOut motor_LB(D6);
PwmOut led_B(A1);
PwmOut led_G(A2);
PwmOut led_R(A5);
PwmOut buzzer(D5);
AnalogIn batteryCheck(A0);
const uint16_t addr = NODE_ADDR;
struct payload_t
{
unsigned long ms;
unsigned long counter;
};
void beepStart();
void endBeep();
void goForward();
int main() {
led_R=1;
led_G=1;
led_B=1;
beepStart();
pc.baud(115200);
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ addr);
wait_ms(2000);
// Display the (default) setup of the nRF24L01+ chip
pc.printf("My ADDR : %d\r\n", NODE_ADDR);
pc.printf("Complete Setting");
beepAfterset();
while(1) {
network.update();
while ( network.available() )
{
RF24NetworkHeader header_rx;
payload_t payload_rx;
network.read(header_rx,&payload_rx,sizeof(payload_rx));
pc.printf("Received packet # %d at %d ms\n",payload_rx.counter,payload_rx.ms);
}
}
}
void goForward()
{
motor_RA = 0.5;
motor_RB = 0;
motor_LA = 0;
motor_LB = 0.5;
}
void onLED(int r, int g, int b)
{
}
/*
// The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
// "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
// only handles 4 byte transfers in the ATMega code.
#define TRANSFER_SIZE 4
wait(2.0);
char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
int txDataCnt = 0;
int rxDataCnt = 0;
nrf.powerUp();
nrf.setTxAddress(0xE7E7E7EF, 4);
// Display the (default) setup of the nRF24L01+ chip
pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", nrf.getRfFrequency() );
pc.printf( "nRF24L01+ Output power : %d dBm\r\n", nrf.getRfOutputPower() );
pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", nrf.getAirDataRate() );
pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", nrf.getTxAddress() );
pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", nrf.getRxAddress() );
pc.printf( "nRF24L01+ CRCWidth : %d \r\n", nrf.getCrcWidth() );
pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
nrf.setTransferSize( TRANSFER_SIZE );
nrf.setReceiveMode();
nrf.enable();
while (1) {
// If we've received anything over the host serial link...
if ( pc.readable() ) {
// ...add it to the transmit buffer
txData[txDataCnt++] = pc.getc();
// If the transmit buffer is full
if ( txDataCnt >= sizeof( txData ) ) {
// Send the transmitbuffer via the nRF24L01+
nrf.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
txDataCnt = 0;
}
endBeep();
}
// If we've received anything in the nRF24L01+...
if ( nrf.readable() ) {
// ...read the data into the receive buffer
rxDataCnt = nrf.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.putc( rxData[i] );
}
beepStart();
}
}
*/