   // 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);
-  
-    
+  int a_verticalRollingSampleMedian=a_verticalRollingSample.getMedian()-a_vertical_offset; 
+  
   // 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) {
+  if (a_verticalRollingSampleMedian >= 80 && abs(a_forwardRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation != POSITION_6) {
     // 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) {
+    orientation = POSITION_6;
+  } else if (a_forwardRollingSampleMedian >= 80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation != POSITION_2) {
     // 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) {
+    orientation = POSITION_2;
+  } else if (a_verticalRollingSampleMedian <= -80 && abs(a_forwardRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation != POSITION_5) {
     // 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) {
+    orientation = POSITION_5;
+  } else if (a_forwardRollingSampleMedian <= -80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_sidewayRollingSampleMedian) <= 25 && orientation != POSITION_1) {
     // 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) {
+    orientation = POSITION_1;
+  } else if (a_sidewayRollingSampleMedian >= 80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_forwardRollingSampleMedian) <= 25 && orientation != POSITION_3) {
     // 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) {
+    orientation = POSITION_3;
+  } else if (a_sidewayRollingSampleMedian <= -80 && abs(a_verticalRollingSampleMedian) <= 25 && abs(a_forwardRollingSampleMedian) <= 25 && orientation != POSITION_4) {
     // coté batteries en haut
-    orientation_boutons = EN_ARRIERE;
+    orientation = POSITION_4;
   }  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;
+
+  /*
+  // for debugging
+  Serial.print("a_forward:");
+  Serial.print(a_forwardRollingSampleMedian);
+  Serial.print(" a_sideway:");
+  Serial.print(a_sidewayRollingSampleMedian);
+  Serial.print(" a_vertical:");
+  Serial.print(a_verticalRollingSampleMedian);
+  Serial.print(" - ");
+  Serial.print(position_stecchino[orientation]);
+  Serial.print(" - ");
+  Serial.print(accel_status);
+  Serial.print(" - ");
+  Serial.println(angle_2_horizon);
+  */
+  
+   return angle_2_horizon;
  }
 
 

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(38400);
  while (!Serial);

  pinMode(PushB1,INPUT);

  accelgyro.initialize();  
  Serial.println("Starting MPU... ");
  
  //a_forward_offset=0;
  //a_sideway_offset=0;
  //a_vertical_offset=-100;

  //delay(2000);
  Vcc=int(readVcc());
  Serial.print("VCC=");
  Serial.print(Vcc);
  Serial.println("mV");
  CHECK_BATTERY_LED(Vcc);
  delay(2000);
  alloff();
  
  start_time=millis();
}

// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = {confetti, sinelon, juggle, bpm, rainbow};
char* SimplePatternNames[]={"confetti","sinelon", "juggle", "bpm", "rainbow" };
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
uint8_t gFrameCount = 0; // Inc by 1 for each Frame of Trasition, New/Changed connection(s) pattern


void LEDS_ON(int count, int record){
    for (int i = NUM_LEDS; i >=0; i--) {
