 volatile uint8_t bUpdateFlagsShared;
 
 // shared variables are updated by the ISR and read by loop.
-// In loop we immediatley take local copies so that the ISR can keep ownership of the 
+// In loop we immediatley take local copies so that the ISR can keep ownership of the
 // shared ones. To access these in loop
 // we first turn interrupts off with noInterrupts
 // we take a copy to use in loop and the turn interrupts back on


void loop()
{
  // create local variables to hold a local copies of the channel inputs
  // these are declared static so that thier values will be retained 
  // between calls to loop.
  static uint16_t unThrottleIn;
  static uint16_t unYawIn;
  static uint16_t unPitchIn;
  static uint16_t unRollIn;
  // local copy of update flags
  static uint8_t bUpdateFlags;

  // check shared update flags to see if any channels have a new signal
  if(bUpdateFlagsShared)
    {
      noInterrupts(); // turn interrupts off quickly while we take local copies of the shared variables

      // take a local copy of which channels were updated in case we need to use this in the rest of loop
      bUpdateFlags = bUpdateFlagsShared;
    
      // in the current code, the shared values are always populated
      // so we could copy them without testing the flags
      // however in the future this could change, so lets
      // only copy when the flags tell us we can.
    
      if(bUpdateFlags & THROTTLE_FLAG)
	{
	  unThrottleIn = unThrottleInShared;
	}
    
      if(bUpdateFlags & YAW_FLAG)
	{
	  unYawIn = unYawInShared;
	}
    
      if(bUpdateFlags & PITCH_FLAG)
	{
	  unPitchIn = unPitchInShared;
	}

      if(bUpdateFlags & ROLL_FLAG)
	{
	  unRollIn = unRollInShared;
	}
     
      // clear shared copy of updated flags as we have already take
      // we still have a local copy if we need to use it in bUpdateFlags
      bUpdateFlagsShared = 0;
    
      interrupts(); // we have local copies of the inputs, so now we can turn interrupts back on
      // as soon as interrupts are back on, we can no longer use the shared copies, the interrupt
      // service routines own these and could update them at any time. During the update, the 
      // shared copies may contain junk. Luckily we have our local copies to work with :-)
    }
  
  bUpdateFlags = 0;
}


// On request I2C data Sends shared values the Remote values
// for Throttle, Yaw, Pitch and Roll
// Note interrupts sotpped while sending values, should not 
// take much time
void SendRemote()
{


//define Servo variables
Servo MOTOR[SERVO_NUM];

//servo values updated by Rpi
volatile union int_byt{
  uint8_t b[2];
  uint16_t i;
} *rcv_data = new int_byt[SERVO_NUM];



void setup()
{
