 #include <avr/sleep.h> // Librairies for sleep mode
 #include <avr/io.h> // Librairies for sleep mode
 
+// Definitions
 #define NUM_LEDS 72  // How many leds in your strip?
 #define HIGH_BRIGHTNESS 50  // Set LEDS brightness
 #define LOW_BRIGHTNESS 10  // Set LEDS brightness

  // Get median
  int a_forwardRollingSampleMedian=a_forwardRollingSample.getMedian()-a_forward_offset;
  int a_sidewayRollingSampleMedian=a_sidewayRollingSample.getMedian()-a_sideway_offset;
  //int a_verticalRollingSampleMedian=a_verticalRollingSample.getMedian()-a_vertical_offset+100;
  int a_verticalRollingSampleMedian=a_verticalRollingSample.getMedian()-a_vertical_offset-100; 
  
  // for debugging
  //Serial.print("a_forward:");
  //Serial.print(a_forwardRollingSampleMedian);
  //Serial.print(" a_sideway:");
  //Serial.print(a_sidewayRollingSampleMedian);
  //Serial.print(" a_vertical:");
  //Serial.println(a_verticalRollingSampleMedian);
  
    
  // Evaluate current condition based on smoothed accelarations
  accel_status="unknown";
  if (abs(a_sidewayRollingSampleMedian)>abs(a_verticalRollingSampleMedian)||abs(a_forwardRollingSampleMedian)>abs(a_verticalRollingSampleMedian)){accel_status="fallen";}
  if (abs(a_sidewayRollingSampleMedian)<abs(a_verticalRollingSampleMedian)&&abs(a_forwardRollingSampleMedian)<abs(a_verticalRollingSampleMedian)){accel_status="straight";}
  //else {accel_status="unknown";}

  if (a_verticalRollingSampleMedian >= 80 && abs(a_forwardRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation_boutons != EN_HAUT) {
    // coté 1 en haut
    orientation_boutons = EN_HAUT;
  } else if (a_forwardRollingSampleMedian >= 80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation_boutons != AU_DESSUS) {
    // coté 2 en haut
    orientation_boutons = AU_DESSUS;
  } else if (a_verticalRollingSampleMedian <= -80 && abs(a_forwardRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation_boutons != EN_BAS) {
    // coté 3 en haut
    orientation_boutons = EN_BAS;
  } else if (a_forwardRollingSampleMedian <= -80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation_boutons != AU_DESSOUS) {
    // coté 4 en haut
    orientation_boutons = AU_DESSOUS;
  } else if (a_sidewayRollingSampleMedian >= 80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_forwardRollingSampleMedian) <= 25 && orientation_boutons != EN_AVANT) {
    // coté LEDs en haut
    orientation_boutons = EN_AVANT;
  } else if (a_sidewayRollingSampleMedian <= -80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_forwardRollingSampleMedian) <= 25 && orientation_boutons != EN_ARRIERE) {
    // coté batteries en haut
    orientation_boutons = EN_ARRIERE;
  }  else {
    // orientation = FACE_NONE;
  }
  
 //Serial.print(" - ");
 //Serial.print(position_boutons[orientation_boutons]);
 //Serial.print(" - ");
 //Serial.println(accel_status);

 angle_2_horizon=atan2(float(a_verticalRollingSampleMedian),float(max(abs(a_sidewayRollingSampleMedian),abs(a_forwardRollingSampleMedian))))*180/PI;
 //Serial.print(" ");
 //Serial.println(angle_2_horizon);
 return angle_2_horizon;
 }



float CheckAccel(){
  // Reads acceleration from MPU6050 to evaluate current condition.
  // Tunables: 
  // Output values: accel_status=fallen or straight
  //                orientation=POSITION_1 to POSITION_6
  //                angle_2_horizon
  // Get accelerometer readings
  accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  float angle_2_horizon=0;

  // Offset accel readings
  //int a_forward_offset = -2;
  //int a_sideway_offset = 2;
  //int a_vertical_offset = 1;

  // Convert to expected orientation - includes unit conversion to "cents of g" for MPU range set to 2g
