         cbi(PORTC, PORTC6);     // digitalWrite(S_DEC1, LOW);
         cbi(PORTD, PORTD7);     // digitalWrite(S_DEC2, LOW);
     }
+}
+
+
+// -------------------------------------------------------------------------------------------------
+void delayPeriod(byte expectedSingal)
+{
+    timeoutStart = millis();
+    while (SignalsReceived < expectedSingal) 
+    {
+        if ((millis() - timeoutStart) > TIMEOUT_PERIOD) { break; }
+    }
+    
+    delay(ROUND_DELAY);
 }
 
 

    range[2]  = (timeRight - timeStart) / SCALE_FACTOR;
    range[6]  = (timeCenter - timeStart) / SCALE_FACTOR;

    analogRange[11] = analogRead(AN11);
    analogRange[2] =  analogRead(AN2);
    analogRange[6] =  analogRead(AN6);


    //TO DO: Receive data from rear board
    writeOutput();
    boardState = READY;
    roundCount++;
}


#define ROUND_DELAY     100 //ms between rounds, seems to help stability

//Modify EXPECTED_SIGNALS to match which sonars are on the board.
#define EXPECTED_SIGNALS1    3
#define EXPECTED_SIGNALS2    3
#define EXPECTED_SIGNALS3    2
#define COMMAND_GO           1
#define RANGE_DATA_SIZE     13
// -------------------------------------------------------------------------------------------------

//Bit Manipulation Functions
#define cbi(port, bit) (port &= ~(1 << bit))        //Clear a bit
#define sbi(port, bit) (port |= (1 << bit))         //Set a bit
#define tbi(port, bit) (port ^= (1 << bit))         //toggle a bit
#define ibh(port, bit) ((port & (1 << bit)) > 0)    //Is a bit high
#define ibl(port, bit) ((port & (1 << bit)) == 0)   //Is a bit low
// -------------------------------------------------------------------------------------------------

enum STATE : byte { INITIAL, READY, ROUND1, ROUND2, ROUND3 };
STATE boardState;   //initializing sonar board state

// enum SONAR : byte {};

volatile byte SignalsReceived;
volatile unsigned long timeLeft;
