 RunningMedian a_verticalRollingSample = RunningMedian(5);
 #define ACCELEROMETER_ORIENTATION 2     // 0, 1 or 2 to set the angle of the joystick
 int a_forward_offset=0,a_sideway_offset=0,a_vertical_offset=0;
-
+enum POSITION_BOUTONS { NONE, EN_HAUT,AU_DESSUS,EN_BAS,AU_DESSOUS, EN_AVANT, EN_ARRIERE, COUNT };  // Used to detect position of buttons relative to Stecchino and user
+const char *position_boutons[COUNT] = { "None", "EN_HAUT", "AU_DESSUS", "EN_BAS", "AU_DESSOUS", "EN_AVANT", "EN_ARRIERE" };
+uint8_t orientation_boutons = NONE;
 
 unsigned long start_time=0, current_time=0, elapsed_time=0, record_time=0, previous_record_time=0;
 int i=0;
+float angle_2_horizon=0;
 
 CRGB leds[NUM_LEDS];  // Define the array of leds
 
 void setup() {
 
-  Serial.begin(9600);
+  Serial.begin(38400);
   while (!Serial);
 
   pinMode(PushB1,INPUT);

#define Button_1_On  (!digitalRead(PushB1))
#define FRAMES_PER_SECOND  120
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
#define SET_IDLE_MILLISECONDS 20000 // how many seconds at idle before moving to sleep?
#define NUM_LEDS_PER_SECONDS 2 // how many LEDs are turned on every second when playing?

// Variables used in CheckAccel() routine

  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;
 }


void sleepNow(void)
