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:
- 0:2dade6db4d3a
- Child:
- 1:450bd5ee8cdc
File content as of revision 0:2dade6db4d3a:
#include "mbed.h"
#include "RF24.h"
#include "tone.h"
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);
RF24 nrf(D11,D12,D13,D2,A3);
AnalogIn batteryCheck(A0);
void startBeep();
void endBeep();
void goForward();
uint8_t id = 0;
uint8_t rxAddr[10][6] = {"BOT0R","BOT1R","BOT2R","BOT3R","BOT4R","BOT5R","BOT6R","BOT7R","BOT8R","BOT9R"};
uint8_t txAddr[10][6] = {"BOT0T","BOT1T","BOT2T","BOT3T","BOT4T","BOT5T","BOT6T","BOT7T","BOT8T","BOT9T"};
int main() {
led_R=1;
led_G=1;
led_B=1;
startBeep();
pc.baud(115200);
nrf.begin();
nrf.stopListening();
nrf.openWritingPipe(txAddr[id]);
nrf.openReadingPipe(1,rxAddr[id]);
nrf.setChannel(101);
// Display the (default) setup of the nRF24L01+ chip
pc.printf( "My ID : %d", id);
pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", 2000+nrf.getChannel() );
pc.printf( "nRF24L01+ Output power : %d dBm\r\n", nrf.getPALevel() );
pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", nrf.getDataRate() );
pc.printf( "nRF24L01+ TX Address : 0x%X%X%X%X%X\r\n", rxAddr[id][0], rxAddr[id][1], rxAddr[id][2], rxAddr[id][3], rxAddr[id][4]);
pc.printf( "nRF24L01+ RX Address : 0x%X%X%X%X%X\r\n", txAddr[id][0], txAddr[id][1], txAddr[id][2], txAddr[id][3], txAddr[id][4]);
pc.printf( "nRF24L01+ CRCWidth : %d Byte\r\n", nrf.getCRCLength() );
//goForward();
while(1) {
pc.printf("%f\r\n", batteryCheck.read());
wait(0.3);
}
}
void startBeep()
{
buzzer.write(0.5);
buzzer.period_us(1000000/Do5);
wait(0.1);
buzzer.period_us(1000000/Mi5);
wait(0.1);
buzzer.period_us(1000000/So5);
wait(0.1);
buzzer.write(0);
}
void endBeep()
{
buzzer.write(0.5);
buzzer.period_us(1000000/So5);
wait(0.1);
buzzer.period_us(1000000/Mi5);
wait(0.1);
buzzer.period_us(1000000/Do5);
wait(0.1);
buzzer.write(0);
}
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] );
}
startBeep();
}
}
*/