-#include <avr/sleep.h>
+#include "LowPower.h"
 
 const int OBSTACLE_SENSOR = 2;
-const int OBSTACLE_BATTERY = 5;
-const int BUZZER = 3;
+const int OBSTACLE_BATTERY = 3;
+const int LED = 5;
+const int BUZZER = 9;
 const int BUZZER_BATTERY = 6;
 const int SOUND_DURATION = 40;
 const int RANDOM_ERROR_COUNT = 20;
+const int COUNT_BEFORE_SLEEP = 30;
 int lastObstacleValue;
-
-/**
- * Sleep mode
- */
-void sleep() {
-  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
-  
-  noInterrupts();
-  sleep_enable();
-  attachInterrupt(digitalPinToInterrupt(OBSTACLE_SENSOR), onObstacleChanged, CHANGE);
-  interrupts();
-  
-  sleep_cpu();
-}
-
-/**
- * Wake up
- */
-void wake() {
-  sleep_disable();
-  detachInterrupt(digitalPinToInterrupt(OBSTACLE_SENSOR));
-}
-
-/**
- * Obstacle sensor is changed
- */
-void onObstacleChanged() {
-  wake();
-}
 
 /**
  * Setup
  */
 void setup() {
+  pinMode(LED, OUTPUT);
   pinMode(BUZZER, OUTPUT);
   pinMode(BUZZER_BATTERY, OUTPUT);
   pinMode(OBSTACLE_SENSOR, INPUT);

 * Main loop
 */
void loop() {
  digitalWrite(OBSTACLE_BATTERY, 255);
  digitalWrite(BUZZER_BATTERY, 255);
  int obstacleValue = digitalRead(OBSTACLE_SENSOR);
  
  if (lastObstacleValue == HIGH && obstacleValue == LOW) {
      int randNumber = random(RANDOM_ERROR_COUNT);
      if (randNumber == 0) {
          soundError();
      } else {
          soundOk();
      }
  }
  lastObstacleValue = obstacleValue;

  sleep();
}

/**

        delay(1);
    }
}

/**
 * Wake up
 */
void wake() {
  
}
