Problem with sending an array of bytes including start & end markers

I’m trying to send an array of bytes including start and end markers between two Arduino Leonardos using Serial1 and Bluetooth modules HC-06 and HC-05 set as master and slave, but the code isn’t working. Any help would be much appreciated!

The array code and serial TX/RX code are the result of a lot of reading over the closest examples that I’ve been able to find. The hardware is all proven out, in that the switches and pot circuits work properly, there’s an LED that shows communication being established between the Bluetooth modules, and when transmitting a single byte of “0” or “1” (a single switch to actuate a single LED lamp) instead of an array, everything works perfectly. So I believe the problem is in the array transmission, receiving, and/or processing.

I’ve made sure that each data element to be transmitted is one byte long, to prevent any complications with multiple bytes per data element.

Here’s the code for the master unit, minus all the button variables setup and button press handling, which has been thoroughly proven out.

#define startMarker 254
#define endMarker 255
byte valueMainLamps;  
byte valueLEDRings;  
byte potValue;  
byte controls[] = {startMarker, valueMainLamps, valueLEDRings, potValue, endMarker};

void setup()  
{
Serial1.begin(9600);  
}  

void loop()  
{
  potValue = analogRead(potPin)/4;  //  Read the value of the analog pot at pin A0 on a scale of 0 to 1023 and divide it by 4 for a range of 0-255
  if (potValue == 254)  //  Test for "startMarker" binary equivalent, change to a safe value
  {
    potValue = 253;  
  }
  if (potValue == 255)  //  Test for "endMarker" binary equivalent, change to a safe value
  {
    potValue = 253; 
  }
Serial1.write(controls, 5); 
delay (50);
}

Here’s the code for the slave unit minus a lot of the NeoPixel LED processing and other LED-specific code, which I’m not showing here since it also has been proven out.

byte valueMainLamps; 
int stateMainLamps;
byte valueLEDRings; 
int stateLEDRings;
byte potValue;
int bytesRecvd; 
boolean inProgress; 
byte startMarker = 254;
byte endMarker = 255;

//  The data buffer array holds the received bytes
byte dataBuffer[3];  
byte mainLEDsByte; 
byte ledRingsByte; 
byte potByte;
byte x;  //  This is used in a counter inside the getSerialData function. 

void setup()  
{
valueMainLamps = 0;  //  Set the main lamps to off by default
stateMainLamps = LOW;  
valueLEDRings = 0;  //  Set the LED rings to off by default 
stateLEDRings = LOW;
potValue = 0;  //  Set the LED rings intensity to zero to start
Serial1.begin(9600);  
}  

void loop()  
{
getSerial1Data();  mainLEDsByte = dataBuffer[0]; 
ledRingsByte = dataBuffer[1];
potByte = dataBuffer[2];

valueMainLamps = (int) mainLEDsByte;  //  Cast (convert) the byte value in each array location to an int so that it can set output values appropriately. 
valueLEDRings = (int) ledRingsByte; 
potValue = (int) potByte; 

// Turn the LEDs on or off
if (valueMainLamps == 0) 
  {
    stateMainLamps = LOW; 
  }
if (valueMainLamps == 1)
  {
    stateMainLamps = HIGH; 
  }
digitalWrite(pinMainLamps, stateMainLamps);

// Set the colors in the NeoPixel ring by combining the pot level with the test values set for each color, and output LED ring level calculations
if (stateLEDRings == HIGH)  //  Do the regular levels for the LED rings if the LEDs are on
  {
  //  Not showing the LED rings code here since it all works.
  }

// Set the LED colors, using the format:  nthRing.setPixelColor(Pixel Number, G, R, B, W))      
  for(i=0; i < 17; i++)
    {
      firstRing.setPixelColor(i, greenLevel, redLevel, blueLevel, whiteLevel);
    }

// Update the LED rings
firstRing.show();
}

void getSerial1Data() 
{
if (Serial1.available() > 0)  // Receives data into dataBuffer[]
  {  
    x = Serial1.read();
    if (x == startMarker) 
    { 
      bytesRecvd = 0; 
      inProgress = true;
    }  
    if(inProgress == true) 
    {
      dataBuffer[bytesRecvd] = x;
      bytesRecvd ++;
    }
    if (x == endMarker)   
    {
      inProgress = false;
    }
  }
}

The values in the array are NOT bound to the variables used to provide initial values. Frankly, those variables are useless. Just put the value in the array.

You need one if test, not two: if(potValue >= 254)

getSerialData() may, or may not get anything. At most, it gets one byte. Yet, you expect that, somehow, magically, the function will have gotten 5 bytes and stored three of them in the array.