//Master Arduino Code:

#include <SPI.h>   //Library for SPI 
#define ROWS 6
#define COLS 5

byte jointPositions[ROWS][COLS] = 
{
{13, 20, 10, 3, 239},
{13, 205, 10, 120, 50},                
{13, 20, 10, 120, 70},
{13, 20, 239, 120, 205},
{13, 205, 10, 120, 110},
{13, 20, 10, 120, 170},
};

void setup (void)
{
  Serial.begin (9600);                    //Starts Serial Communication 
  digitalWrite(SS, HIGH);                 // ensure SS stays high for now
  SPI.begin ();                           //Begins the SPI commnuication
  SPI.setClockDivider(SPI_CLOCK_DIV8);    //Sets clock for SPI communication at 8 (16/8=2Mhz)

}  // end of setup


void loop (void)
{
  byte Message;
    
for ( byte i = 0 ; i < ROWS ; i++)
    {
          
   
 digitalWrite(SS, LOW); 
 delayMicroseconds (5);
 byte z = SPI.transfer (0xCD);       //are you there
 delayMicroseconds(5);             //give the slave time to process
 byte x = SPI.transfer (0);          //0x00 is sent to get response byte
delayMicroseconds(5);
 Serial.println("");
 
  if (x == 0xEF)
  {
      for (byte j = 0 ; j < COLS ; j++)
      {
       
       Message = (jointPositions[i][j]);               //preparing data to send
       byte FinalMessage = SPI.transfer (Message);  //sending data
       delayMicroseconds(20);                       //give the slave time to process
       Serial.print(jointPositions[i][j]);
       Serial.println();
      }
             
  // disable Slave Select
  delay(2000);
  digitalWrite(SS, HIGH); 
  Serial.println();
  Serial.println("=================");
    }
    
  }
  

  
}   // end of loop
