  * ISR for pin 2 (int.0)
  */
 void isrMotion() {
-  // Tell the loop to power up the ping sensors.
-  pingPowerState = 1;
-  // Rest the awake time.
-  awakeTime = 0;
+  bitSet(flags, F_MOTION);
 }
 
 void setup() 
 {
   Serial.begin(115200);
+  
+  bitClear(flags, F_MOTION);
+  bitClear(flags, F_LEFT);
+  bitClear(flags, F_RIGHT);
   
   pinMode(PIN_PING_POWER, OUTPUT);
   

    
    transmit(buf); 
  }
  
}


  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
    
  // Add the external interupt to the PIR.
  attachInterrupt(0, isrMotion, RISING);
    
}

void loop() 
{
  
  // The motion ISR sets a flag so we know it detected motion.
  if (bitRead(flags, F_MOTION)) {
    bitClear(flags, F_MOTION);
    if (pingPowerState == 0) {
      // Remember when the cpu woke up.
      awakeTime = millis();
    }
    
    // Ensure the ping sensors are powered.
    pingPowerState = 1;
    // Turn on the ping power.
    digitalWrite(PIN_PING_POWER, HIGH);
  }
  
  if (pingPowerState == 0) {
    // Turn off the power to the ping sensors.
    digitalWrite(PIN_PING_POWER, LOW);
    
    // Deep sleep until the next motion.
    sleepNow();
  } 
  
  
  
  
  // PING )))
  for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
