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
- Branch:
- RF24_library_test_tx
- Revision:
- 11:1b56bb8ccd04
- Parent:
- 10:02d3ca034103
- Child:
- 12:cf6cbf1d1ebf
--- a/main.cpp Sun Nov 25 11:31:55 2018 +0000
+++ b/main.cpp Sun Nov 25 12:39:01 2018 +0000
@@ -35,6 +35,8 @@
void beepStart();
void endBeep();
void initNRF(int role);
+void dumpRFInfo();
+void turnWheel(int rspd, int lspd);
void getPayload(int id, unsigned int count, int lspeed, int rspeed, char* txData);
@@ -48,15 +50,14 @@
beepStart();
pc.baud(115200);
- // Print setting of radio module
+ initNRF(role);
+ dumpRFInfo();
- initNRF(role);
-
while(1) {
if(role == PING) {
int id = 1;
- int lspeed=-90;
- int rspeed=23;
+ int lspeed=-40;
+ int rspeed=50;
//printf("transmitting\r\n");
txDataCnt++;
getPayload(id, txDataCnt, lspeed, rspeed, txData);
@@ -69,6 +70,14 @@
if ( nrf.readable() ) {
rxDataCnt = nrf.read( NRF24L01P_PIPE_P0, rxData, TRANSFER_SIZE);
printf("%s\r\n", rxData);
+ int rspd = (rxData[8]-'0')*10+(rxData[9]-'0');
+ int lspd = (rxData[11]-'0')*10+(rxData[12]-'0');
+ if(rxData[7]=='-')
+ rspd = -rspd;
+ if(rxData[10]=='-')
+ lspd = -lspd;
+ turnWheel(rspd, lspd);
+ printf("%d, %d\r\n", rspd,lspd);
}
}
}
@@ -80,15 +89,17 @@
motor_RA.write((float)rspd/100);
motor_RB = 0;
} else {
+ rspd=-rspd;
motor_RB.write((float)rspd/100);
motor_RA = 0;
}
if(lspd>0) {
motor_LA.write((float)lspd/100);
- motor_LB = 1;
+ motor_LB = 0;
} else {
+ lspd = -lspd;
motor_LB.write((float)lspd/100);
- motor_LA = 1;
+ motor_LA = 0;
}
}