 //=============================================================================//
 void loop()
 {
-    // GET MOTION
-    //-------------------------------------------------------------------------//
     unsigned long currentG = millis(); // millis();
 
     if (currentG - trigG  >= trigGyro) 
     {
     	trigG = currentG;
       
-      
+         // GET MOTION
+         //-------------------------------------------------------------------------// 
     	accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
-		if(invertXY)
-		{
-			y = (((ax/180)+etalonX)+90);
-  			x = (((ay/180)+etalonY)+90);
-		}
-		else
-		{
-			x = (((ax/180)+etalonX)+90);
-  			y = (((ay/180)+etalonY)+90);
-		}
+	if(invertXY)
+	{
+	    y = (((ax/180)+etalonX)+90);
+  	    x = (((ay/180)+etalonY)+90);
+	}
+	else
+	{
+	    x = (((ax/180)+etalonX)+90);
+  	    y = (((ay/180)+etalonY)+90);
+	}
     }
   
-    // GET SERIAL DATA
+    // GET SERIAL AND RF24 DATA
     //-------------------------------------------------------------------------//
 	  
     char msg[64];

    {
    	Serial.readBytesUntil('\n', msg, sizeof msg);
    	newData = true;
	}
	
	if (radio.available())
    {
    	char msg[64] = {0};
    	radio.read(&msg, sizeof(msg));
    	newData = true;
    }
	
	if(newData)
	{
		Serial.println(msg);
		newData = false;
		
    	if (strcmp(strtok(msg, " "), "SET") == 0)
    	{
        	Serial.println("UPDATE SETPOINT");
      		// trouvé le message
      		char *p;
      		while ((p = strtok(NULL, " ")) != NULL)
      		{
        		int val = atoi(p + 1);
        		switch (*p)
        		{
          			case 'x': setpointX  = val; break;
          			case 'y': setpointY  = val; break;
      	  			case 'm': multiplier = val; break;
      				case 'i': invertXY   = val; break;
      				case 'j': invertX    = val; break;
      				case 'k': invertX    = val; break;
      				case 'h': hysteresis = val; break;
        		}
      		}
    	}
    
    	if (strcmp(strtok(msg, " "), "RUN") == 0)
    	{
        	Serial.println("ROll BB-8 ROLL !");
      	    production = true;
    	}
    
    	if (strcmp(strtok(msg, " "), "STOP") == 0)
    	{
    		Serial.println("STOP");
    	    production = false;
    	}
    	
    	if (strcmp(strtok(msg, " "), "RESET") == 0)
    	{
    		Serial.println("RESET");
    	    production = false;
    	    emgStop    = false;
    	}
    	
    	if (strcmp(strtok(msg, " "), "BOOT") == 0)
    	{
    		
    	    BOOT = true;
    	    Serial.println("BOOTING UP...");
    	    delay(2000);

	k = INVERT the direction of Y
	h = SET a new HYSTERESSIS 

  < BOOT > 
  'BOOT \n'  // LAUNCH TEST for X, Y and Z -> Return X and Y to initial SETPOINT (x90 y90 ) and Z to ZERO

  < RUN >
  'RUN \n'   // RUN the code in production mode (Recieved all data, X and Y runing for the SETPOINT poistion and Z folow the remote controll
  
  < STOP >   
  'STOP \n'  // STOP the production mode. All motors are stopped.
  
  < ROTATE >
  'ROTATE d1 s100 \n'   // ROTATE Z motor on the RIGHT DIRECTION (d0 LEFT, d1 RIGHT) WITH the SPEED at 1000/100 = 10 step/sec = 18dec/sec
  
  < STAT >
  // It is all data SENDED to the remote
  
  < ENABLE > 
  'ENABLE a1 x1 z1 \n'    // ENABLE MOTOR AB, XY and Z (a = AB, x=XY, z = Z | 0 = desabled | 1 = enabled )
  
*/

