Add a circular signal to a circular signal. Almost works!

Hello,
10 ball turn in a clock way. By tapping ‘b’ you can see the same circular movement on the 10 balls and by tapping ‘q’ you can see a circular signal added itself to one different ball each 200 ms.
I’m trying to have the absolute position of each ball. It works but if fail only with last one.

import peasy.*;
PeasyCam cam;

// change these for screen size
float w = 600;
float h = 600;

// don't change these
float w2 = w / 2;
float h2 = h / 2;

int nbBall = 10;
//******************         FollowMovement
int formerDecayTime, decayTime;
int networkSize = 12;
int NumberofStep = 6400;
int formerFormerKey;
int formerKey;

float [] phaseFollowLFO= new float[networkSize]; // 
float [] oldPosF= new float[networkSize]; // 
float [] newPosF= new float[networkSize]; //
int [] oldPositionToMotor= new int[networkSize]; //
int [] positionToMotor=  new int [networkSize]; //
float [] oldLfoPhase=  new float[networkSize]; //
float [] lfoPhase=  new float[networkSize]; //
float [] LFO=  new float[networkSize]; //
int []  dataMappedForMotor = new int[networkSize ];
//float [] phaseShiftingFollowLFO = new float[12];
float phaseShiftingFollowLFO;
float timeLfo;
int decayTimeLfo;
int formerDecayTimeLfo;
int [] rev = new int[networkSize]; // counter of revolution
int [] revLfo = new int[networkSize]; // counter of revolution

float [] newPosX =  new float[networkSize]; //;
float [] oldPosX =  new float[networkSize]; //;

char letter;
boolean doA,doQ;
int oscillatorChange;

int decayTimeBis;
int formerDecayTimeBis;
int formerKeyMetro;

float x,y,displacement,side;

public void settings() {
  size(600, 600, P3D);
} 

void setup(){
 new PeasyCam(this, 2000);
 frameRate(30); 
 formerFormerKey='#';
 key='q';
}

void draw() {
  background (0);
  
  lfoPattern();
   if (key=='b' || key=='c') {
     formerKeyMetro =  key; // choose mode to "follow"  
     }
     
  addSignal (); 
 
 //println(" formerFormerKey " + char (formerFormerKey) + " formerKey " + char (formerKey) + " key " + key)  ;
 formerFormerKey= formerKey;
 formerKey=key;
}  

void  splitTimeLfo() { 
    
  if (formerDecayTimeLfo>decayTimeLfo){
     oscillatorChange=oscillatorChange+1;
    // key='q';
  } 
  formerDecayTimeLfo = decayTimeLfo; 

   int splitTimeLfo = millis()%200; // linear time  to change " oscillator " each 200 ms
   
         oscillatorChange=oscillatorChange%12;
     if (oscillatorChange<=0) {
         oscillatorChange=2;
         }
         decayTimeLfo = splitTimeLfo;
    //     print (" oscillatorChange "); println ( oscillatorChange ); 
      
}

void lfoPattern() {
    float signal1 = PI + (frameCount / 10.0) * cos (1000 / 500.0)*-1;
    float signal2 = PI + (frameCount / 13.0) * cos (1000 / 500.0)*-1;
 
    if (signal1 > 0 )
     lfoPhase[1]= signal1;  // gauche droite vers le hau.t CIRCULAR MODE usefull ?// diffAngle(angle, HALF_PI);//% TWO_PI  // position du point de depart + vitesse * phi constant  ==> ici vitesse du point phases[0] est constante
    else
     lfoPhase[1]= signal1;
    
     if (signal2 > 0 )
     lfoPhase[2]= signal2; 
    else
     lfoPhase[2]= signal2;
  }

void drawBall(int n, float phase) {
//  print (n); print (" "); println (phase);
  pushMatrix();
  translate(-w2, -h2, -1000);
  noStroke();
  float side = height*0.15*1/nbBall;
  float rayon = width/2;
  
  x = rayon*cos(phase); //-300 à 300
  y = rayon*sin(phase);
  
  translate (x, y, 200+(50*5*n)); // 
  translate (100, 100, 200+(50*5*n));
  colorMode(RGB, 255, 255, 255);
  fill( 0, 255, 0 );
  sphere(side*3);
  popMatrix();
}

void addSignal(){
  
   if (formerKeyMetro == 'b' ){
    splitTimeLfo();
    
   if (key=='q' || key=='a') {
     letter = key;   
     }
  switch(letter) {
    case 'q': 
    doA=false;
    doQ=true;
    break;
    case 'a': 
    doA=true;
    doQ=false;
    break;     
    }
  

   if (formerFormerKey == '#') { //  && doA==true
  //    print ("  normal " + frameCount + " lfoPhase[1] " + lfoPhase[1] + " lfoPhase[2] " + lfoPhase[2]);    println (   ); 
      for (int i = 2; i <  networkSize-0; i+=1) { 
       LFO[i] = lfoPhase[1]; 
   if (LFO[i]<0){        
       LFO[i] = phaseFollowLFO[i] -  LFO[i];
       dataMappedForMotor[i]= int (map (LFO[i], 0, -TWO_PI, NumberofStep, 0)); 

       newPosX[i]= map (dataMappedForMotor[i], NumberofStep, 0, 0, -TWO_PI);
  }
       
   else
       LFO[i] = phaseFollowLFO[i] +  LFO[i];
       dataMappedForMotor[i]= (int) map (LFO[i], 0, TWO_PI, 0, NumberofStep);

       newPosX[i]= map (dataMappedForMotor[i], 0, NumberofStep, 0, TWO_PI);
 
   }
  
   if (LFO[oscillatorChange]<0){        
       LFO[oscillatorChange] = phaseFollowLFO[oscillatorChange]-LFO[oscillatorChange]; 
       dataMappedForMotor[oscillatorChange]= int (map (LFO[oscillatorChange], 0, -TWO_PI, NumberofStep, 0)); 

       newPosX[oscillatorChange]= map (dataMappedForMotor[oscillatorChange], NumberofStep, 0, 0, -TWO_PI);
  }
       
   else
       LFO[oscillatorChange] = phaseFollowLFO[oscillatorChange]+LFO[oscillatorChange];
       dataMappedForMotor[oscillatorChange]= (int) map (LFO[oscillatorChange], 0, TWO_PI, 0, NumberofStep);

       newPosX[oscillatorChange]= map (dataMappedForMotor[oscillatorChange], 0, NumberofStep, 0, TWO_PI);
  }
 
   if (doQ==true ){
  //   pendularPattern(); // offset with lfo oscillator by osillator
    print ("  case q phaseFollowLFO " + oscillatorChange + " "  + phaseFollowLFO[oscillatorChange] + " "); print ("  LFOoscillatorChange  "); print (oscillatorChange); print ("   ") ;  print (LFO[oscillatorChange]  ); 
    print (" newPosX[oscillatorChange] " + newPosX[oscillatorChange]);
    for (int i = 2; i <  networkSize-0; i+=1) { 
   //  phaseFollowLFO[oscillatorChange]= PI/10*-oscillatorChange; // to understand
     phaseFollowLFO[oscillatorChange]= lfoPhase[2];
     LFO[oscillatorChange]=  LFO[i]+phaseFollowLFO[i];  // add offset given by pendularPattern
     LFO[oscillatorChange]=  LFO[i]; 
  
   
    if (LFO[i]<0){
   
     dataMappedForMotor[i]= int (map (LFO[i], 0, -TWO_PI, NumberofStep, 0)); 

       newPosX[oscillatorChange]= map (dataMappedForMotor[i], NumberofStep, 0, 0, -TWO_PI);
  //   newPosX[i]= LFO[i];
       }
       
   else
    
    dataMappedForMotor[i]= (int) map (LFO[i], 0, TWO_PI, 0, NumberofStep);  
    
    newPosX[oscillatorChange]= map (dataMappedForMotor[i], 0, NumberofStep, 0, TWO_PI);
    
     } //
 
   }
    print ("  LFO+LFOoscillatorChange  "); print (oscillatorChange); print ("   ") ;  println (LFO[oscillatorChange]  ); 
   
  key='#';// 

     for (int i = 2; i <  networkSize-0; i+=1) {
    drawBall(i, newPosX[i] );

   
     print( " oldPositionToMotor[i]" ); print ( oldPositionToMotor[i]);
    positionToMotor[i]= (int) map (newPosX[i], 0, TWO_PI, 0, NumberofStep); //
    newPosF[i]=positionToMotor[i]%6400;
 //   if (oldPositionToMotor[i]>positionToMotor[i]){
    if ( oldPosF[i]>newPosF[i]){
      revLfo[i]++;
     
    } 
     oldPositionToMotor[i]=  positionToMotor[i];
     oldPosF[i]=newPosF[i];

     print( " positionToMotor[i]" ); print ( positionToMotor[i]);
     print (" revolutionLFO "); print ( i); print ("  "); println (revLfo[i]); 
  }
  } 
  
  }