Commit 8c7adbcc authored by Avamander's avatar Avamander

Merge pull request #218 from wmarkow/217_fix

Fix for #217 GettingStarted enhancement.
parents 50cf850a d0bbfaa2
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
#include "RF24.h" #include "RF24.h"
/****************** User Config ***************************/ /****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool radioNumber = 0;
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */ /* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8); RF24 radio(7,8);
/**********************************************************/ /**********************************************************/
...@@ -21,6 +18,11 @@ byte addresses[][6] = {"1Node","2Node"}; ...@@ -21,6 +18,11 @@ byte addresses[][6] = {"1Node","2Node"};
// Used to control whether this node is sending or receiving // Used to control whether this node is sending or receiving
bool role = 0; bool role = 0;
/**
* Set the role (sending or receiving) and configure the transmission pipes.
*/
void setRole(bool role);
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
Serial.println(F("RF24/examples/GettingStarted")); Serial.println(F("RF24/examples/GettingStarted"));
...@@ -33,13 +35,7 @@ void setup() { ...@@ -33,13 +35,7 @@ void setup() {
radio.setPALevel(RF24_PA_LOW); radio.setPALevel(RF24_PA_LOW);
// Open a writing and reading pipe on each radio, with opposite addresses // Open a writing and reading pipe on each radio, with opposite addresses
if(radioNumber){ setRole(0);
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}
// Start the radio listening for data // Start the radio listening for data
radio.startListening(); radio.startListening();
...@@ -126,12 +122,12 @@ if (role == 1) { ...@@ -126,12 +122,12 @@ if (role == 1) {
char c = toupper(Serial.read()); char c = toupper(Serial.read());
if ( c == 'T' && role == 0 ){ if ( c == 'T' && role == 0 ){
Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK")); Serial.println(F("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
role = 1; // Become the primary transmitter (ping out) setRole(1); // Become the primary transmitter (ping out)
}else }else
if ( c == 'R' && role == 1 ){ if ( c == 'R' && role == 1 ){
Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK")); Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
role = 0; // Become the primary receiver (pong back) setRole(0); // Become the primary receiver (pong back)
radio.startListening(); radio.startListening();
} }
...@@ -140,3 +136,16 @@ if (role == 1) { ...@@ -140,3 +136,16 @@ if (role == 1) {
} // Loop } // Loop
void setRole(bool newRole)
{
role = newRole;
if(role){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment