Need help Switching pipes on RF24

Hi I'm new to programing and I'm trying to communicate with multiple RF24 at different times. I'm using a Arduino nano and I have a rotary encoder to select which RF24 I want to communicate with but the way I'm trying doesn't seem to work. I'd like the value of the rotary encoder to be the pipe number. Dose anyone know a solution.
Thanks

The Transmitter

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10); 

const byte slaveAddress[][6] = 
     {"00001", "00002", "00003", "00004", "00005"};

                    

#include <Wire.h>                    //Lcd Screen
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);

#define encoderPinA 3                // Rotary Encoder
#define encoderPinB 2
int encoderPos = 1;
unsigned int lastReportedPos = 1;
static boolean rotating = false;
boolean A_set = false;
boolean B_set = false;

int upPin=8;                    // Function  Buttons
int downPin=7;
int holdPin=6;
int up;
int down;
int hold;

byte data[6]; 


int dt1 = 100;                     
int dt2 = 500;
int dt3 = 1000;



void setup()
{
 
Serial.begin(9600);
lcd.begin();
lcd.backlight();

pinMode(encoderPinA, INPUT_PULLUP);   
pinMode(encoderPinB, INPUT_PULLUP);
attachInterrupt(0, doEncoderA, CHANGE);
attachInterrupt(1, doEncoderB, CHANGE);

pinMode(upPin, INPUT_PULLUP);
pinMode(downPin, INPUT_PULLUP);
pinMode(holdPin, INPUT_PULLUP);

radio.begin();              // Radio Transmiter RF24
radio.setPALevel(RF24_PA_MIN);

}

void loop(){
Serial.print(encoderPos);
Serial.print("  ");
Serial.print(data[1]);
Serial.print(data[2]);
Serial.println(data[3]);

data[1]=digitalRead(upPin);
data[2]=digitalRead(downPin);
data[3]=digitalRead(holdPin);

rotating = true;                    
if (lastReportedPos != encoderPos) {   
   lastReportedPos = encoderPos;
 } 
 
send();

lcd.clear();
lcd.setCursor(0,0);
lcd.print("Door Number");
lcd.setCursor(13,0);
lcd.print(encoderPos);
lcd.setCursor(0,1);
lcd.print("Select Function");
delay(dt1);


}


void send(){
    radio.stopListening();
    radio.openWritingPipe(slaveAddress[encoderPos]);
    radio.write(&data, sizeof(data));
  
}


void doEncoderA() {                 // Rotary Encoder
if ( rotating ) delay (1);
if ( digitalRead(encoderPinA) != A_set ) {
A_set = !A_set;
if ( A_set && !B_set )
encoderPos += 1;
rotating = false;
}
if (encoderPos >= 5){
  encoderPos=5;
}

}

void doEncoderB() {
if ( rotating ) delay (1);
if ( digitalRead(encoderPinB) != B_set ) {
B_set = !B_set;
if ( B_set && !A_set )
encoderPos -= 1;
rotating = false;
}
if (encoderPos <= 1){
  encoderPos=1;
}

}

The Reciver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 10);

const byte thisSlaveAddress[6] = {"00001"};

const int upPin = 7;
const int downPin = 6;
const int holdPin = 5;

byte data[6];

unsigned long lastRecivedTime = 0;
unsigned long currentTime = 0;

const byte dt1 = 250; 

void setup() {

Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, thisSlaveAddress);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
pinMode(upPin, OUTPUT);
pinMode(downPin, OUTPUT);
pinMode(holdPin, OUTPUT);

}
 
void loop() { 
  
Serial.print("Data:");
Serial.print(data[1]);
Serial.print(" Data:");
Serial.print(data[2]);
Serial.print(" Data:");
Serial.println(data[3]);
    
getData();

    if (data[1] == 1){
      digitalWrite(upPin, HIGH);
    } else {digitalWrite(upPin, LOW); } 
      
    if(data[2] == 1){
      digitalWrite(downPin, HIGH);
    } else {digitalWrite(downPin, LOW); }
      
    if(data[3] == 1){
      digitalWrite(holdPin, HIGH);
    } else {digitalWrite(holdPin, LOW); }
      
delay(dt1);
}


void getData(){
  if (radio.available()){
    radio.read(&data, sizeof(data));
  }
}


I moved your topic to an appropriate forum category @bradley_waldner_mg.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Try adjusting your addresses from:

const byte slaveAddress[][6] = 
     {"00001", "00002", "00003", "00004", "00005"};

to

const byte slaveAddress[][6] = 
     {"10000", "20000", "30000", "40000", "50000"};

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.