If else not working in wireless set up

Hello-

I have 2 Arduinos with the wireless Nrf24L01s.

The transmit has 2 pots and they control the servos on the receive end. This all works fine…

but on the receive end, I want to be able to switch from the transmitted servo control, to the random mode listed in the “else” statement.

I am a beginner and I’ve cobbled these sketches together (you can probably tell). I just can’t get the if…else switch working…
also, if you notice anything else that’s not quite right, please point it out.

thank you, steve

/*-----TRANSMIT-----*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

#define JoyStick_X A0
#define JoyStick_Y A1

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe


/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/*-----( Declare Variables )-----*/
int joystick[2];

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
}


void loop()
{
  joystick[0] = analogRead(JoyStick_X);
  joystick[1] = analogRead(JoyStick_Y);

  radio.write( joystick, sizeof(joystick) );

}
/*-----RECEIVE-----*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe


/*-----( Declare objects )-----*/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

/*-----( Declare Variables )-----*/
int joystick[2];  // 2 element array holding Joystick readings

#include <Servo.h>      // include the servo library

Servo servo1;      
Servo servo2;      

unsigned long prevMillis = 0;
long interval = 500;

int switchPin = 7;

int pos;
int pos2;

void setup()
{
  Serial.begin(9600);
  Serial.println("Nrf24L01 Receiver Starting");
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  ;

  servo1.attach(5);  
  servo2.attach(6);  

  pinMode(switchPin, INPUT);
}

void loop()
{
  if (digitalRead(switchPin) == HIGH)
  {
    // Read the data payload until we've received everything
    bool done = false;
    while (!done)
    {
      int analogValue = joystick[0]; // read the analog input
      int analogValue2 = joystick[1]; // read the analog input

      int servoAngle = map(analogValue, 0, 1023, 60, 120);
      int servoAngle2 = map(analogValue2, 0, 1023, 60, 120);

      // Fetch the data payload
      done = radio.read( joystick, sizeof(joystick) );
      Serial.print("X = ");
      servo1.write(servoAngle);
      Serial.print(" Y = ");      
      servo2.write(servoAngle2);
    }
  }
  else
  {    
    unsigned long newMillis = millis();
    if (newMillis - prevMillis > interval){
      prevMillis = newMillis;

      int pos = random(80, 100);
      int pos2 = random(50, 130);

      servo1.write(pos);
      servo2.write(pos2);
    }

  }
}

but on the receive end, I want to be able to switch from the transmitted servo control, to the random mode listed in the "else" statement.

So, what's the problem?

The problem is, the servo control works, but my switch on pin 7 does not work. If I upload the sketch without pin 7 high, the random mode works, but once I make it high, it stays in servo control mode and won't switch back, regardless of whether pin 7 is high or not. So it's not switching between modes.

      done = radio.read( joystick, sizeof(joystick) );

Does this actually return true or false? Does it ever actually return true?

      int analogValue = joystick[0]; // read the analog input
      int analogValue2 = joystick[1]; // read the analog input

      int servoAngle = map(analogValue, 0, 1023, 60, 120);
      int servoAngle2 = map(analogValue2, 0, 1023, 60, 120);

      // Fetch the data payload
      done = radio.read( joystick, sizeof(joystick) );
      Serial.print("X = ");
      servo1.write(servoAngle);
      Serial.print(" Y = ");      
      servo2.write(servoAngle2);

Use the data in the array, and then put some data in the array. You've got the horse on the wrong damned end of the cart.