need someone to look at my code to see if im missing something

I’m using an Arduino Mega2560 to control some neopixels but there seems to be a bug that i can’t fined

in the video you can see it working for the first 7 seconds then the left pixels stop turning off and don’t update right. it dose this after i turn on the arduino about 50% of the time i don’t think its sram and I’m getting no error messages

I added the files so you can see all the code that I’m running i add a function to adafruit called setnumpixals();

[/code]

void centeractive(){
  
   bars();
   drop();
   if(lefttimer3<(millis()-100)){
       lefttimer3 = millis();
   getcolor();
   shifttwo();
   addnewcolor();
   } 
   arraytostrip();
stripleft.show();
stripright.show();
}




/// take the lastleft and lastright from bars() and drop() turns them into a usable color 
void getcolor(){
Serial.println("getcolor");
 
     // dettermen the new color and assign to color  
       if(lastleft>=7){
         /// perple 
          colorleft = stripleft.Color(255,0,130);
       }else if(lastleft>=5){
       // red
      colorleft = stripleft.Color(255,0,0);
     }else if(lastleft>=4){
       // blue
       colorleft = stripleft.Color(0,0,255);   
       
     }else if(lastleft>=3){
         // green 
         colorleft = stripleft.Color(0,255,0);
         
      }else if(lastleft>=1){
         // yellow 
         colorleft = stripleft.Color(255,125,0);
        
      }else if(lastleft>=0){
            // wight
            colorleft = stripleft.Color(200,200,200);
      }
   

      
     
     // dettermen the new color and assign to colorright  
       if(lastright>=7){
         // perple 
          colorright = stripright.Color(255,0,130);
       }else if(lastright>=5){
       ///red
        colorright = stripright.Color(255,0,0);
      }else if(lastright>=4){
       // blue
       colorright = stripright.Color(0,0,255);    
      }else if(lastright>=3){
          // green
         colorright = stripright.Color(0,255,0);
      }else if(lastright>=1){
         // yellow 
        colorright = stripright.Color(255,125,0);
        
      }else if(lastright>=0){
            // wight
            colorright = stripright.Color(200,200,200);
            
          }
            
     }

  

/// moves the array into the other array 
void arraytostrip(){
  
  for(int i=0;i<half;i++){
     if(i<lastright){
     stripright.setPixelColor(i,top_arrayright[i]);
     stripright.setPixelColor(i+1,top_arrayright[i+1]);
     stripright.setPixelColor((stripright.numPixels()-i)-1,bottom_arrayright[i]);
     stripright.setPixelColor((stripright.numPixels()-i)-2,bottom_arrayright[i+1]);
     }else{
               stripright.setPixelColor(i,off);
               stripright.setPixelColor(i+1,off);
               stripright.setPixelColor((stripright.numPixels()-i)-1,off);
               stripright.setPixelColor((stripright.numPixels()-i)-2,off);
     }
     i++;
   }

   for(int i=0;i<half;i++){
     if(i<lastleft){
     stripleft.setPixelColor(i,top_arrayleft[i]);
     stripleft.setPixelColor(i+1,top_arrayleft[i+1]);
     stripleft.setPixelColor((stripright.numPixels()-i)-1,bottom_arrayleft[i]);
     stripleft.setPixelColor((stripright.numPixels()-i)-2,bottom_arrayleft[i+1]);
     }else{
      //Serial.println(stripleft.numPixels()-i-1);
               stripleft.setPixelColor(i,off);
               stripleft.setPixelColor(i+1,off);
               stripleft.setPixelColor((stripleft.numPixels()-i)-1,off);
               stripleft.setPixelColor((stripleft.numPixels()-i)-2,off);
     }
     i++;
   }
  
}
///// adds new color to the arrays
void addnewcolor(){

 if((stripright.numPixels()/2)%2){
            
       top_arrayright[half-1] = colorright;
       top_arrayright[half] = colorright;
       bottom_arrayright[half-1] = colorright;
       bottom_arrayright[half] = colorright;

      
    }else{
           

       top_arrayright[half-1] = colorright;
       top_arrayright[half-2] = colorright;
       bottom_arrayright[half-1] = colorright;
       bottom_arrayright[half-2] = colorright;
    }
if((stripleft.numPixels()/2)%2){
            
       top_arrayleft[half-1] = colorleft;
       top_arrayleft[half] = colorleft;
       bottom_arrayleft[half-1] = colorleft;
       bottom_arrayleft[half] = colorleft;

      
    }else{
           

       top_arrayleft[half-1] = colorleft;
       top_arrayleft[half-2] = colorleft;
       bottom_arrayleft[half-1] = colorleft;
       bottom_arrayleft[half-2] = colorleft;
    }

  
}

///// shifts the array over two
void shifttwo(){

if((stripright.numPixels()/2)%2){

 for(byte i=0;i<half;i++){
         top_arrayright[i] = top_arrayright[i+2];
         bottom_arrayright[i] = bottom_arrayright[i+2];   
         
   }
  
 }else{
  
 ////// if even //////////
   for(byte i=0;i<(half-1);i++){
         
         top_arrayright[i] = top_arrayright[i+2];
         bottom_arrayright[i] = bottom_arrayright[i+2]; 
           
   }
   
 }

   ////// if odd /////////////////////////
 if((stripleft.numPixels()/2)%2){

 for(byte i=0;i<half;i++){
         top_arrayleft[i] = top_arrayleft[i+2];
         bottom_arrayleft[i] = bottom_arrayleft[i+2];   
         
   }
  
 }else{
  
 ////// if even //////////
   for(byte i=0;i<(half-1);i++){
         
         top_arrayleft[i] = top_arrayleft[i+2];
         bottom_arrayleft[i] = bottom_arrayleft[i+2]; 
           
   }
   
 }
  
}
///controls how fast the pixels turn off from the center  
void drop(){

//// controls the drop rate of the bars that are lit up /////////// 
   if((lastleft>left)&&(lefttimer1<=(millis()-analogRead(droprate)))&&(lefttimer2 <(millis()-20))){
     lastleft = lastleft-1;
      lefttimer1 = millis();
      lefttimer2 = millis();
    }else if(lastleft<left){
      lastleft = left;
      
      lefttimer1 = millis();
      lefttimer2 = millis()+20;
    }
    
    /////// controls the drope rate of the right bar 
   if((lastright>right)&&(righttimer1<=(millis()-analogRead(droprate)))&&(righttimer2 <(millis()-20))){
     lastright = lastright-1;
      righttimer1 = millis();
      righttimer2 = millis()+20;
    }else if(lastright<right){
      lastright = right;
      
      righttimer1 = millis();
      righttimer2 = millis();
    }



  
}
///  takes audio and turns it into a usable number  
void bars(){

     left = analogRead(leftChannel);  // read the left audio channel
   right = analogRead(rightChannel); // read the right audio channel
   
   left = pow(left,1.2);
   right = pow(right,1.2);

           int sensitivity = map(analogRead(sensitivityinput),0,1023,418,100); // gets and sets senitivity rang
           int minimum = map(analogRead(flux),0,1023,0,(sensitivity-1));  // gets and sets the minimum audio input needed to light first bar 

////////////////////// set limits on left ///////////////////
                       if(left>sensitivity){
                         left = sensitivity;
                         }else if(left<minimum){
                         left = minimum;
                         }
////////////////////// sets limits on right //////////////////
                         if(right>sensitivity){
                           right = sensitivity;
                         }else if(left<minimum){
                           right = minimum;
                           
                         }
                         

         //uses the syntax above and sets a value to represent how meany bars to be lit up                
           right =  map(right,minimum,sensitivity,0,half);            
           left  =  map(left,minimum,sensitivity,0,half); 

  
}

centeractive.ino (6.95 KB)

prototypevumetter1_000.ino (3.69 KB)

Adafruit_NeoPixel.cpp (40.8 KB)

Adafruit_NeoPixel.h (3.16 KB)

       if(lastleft>=7){
         /// perple
          colorleft = stripleft.Color(255,0,130);
       }else if(lastleft>=5){

Igaveuptryingtoreadyourcode.

If you can't be bothered to use spaces to make your code readable, and properly format it, I can't be bothered to read it.

PaulS:

       if(lastleft>=7){

/// perple
          colorleft = stripleft.Color(255,0,130);
      }else if(lastleft>=5){



Igaveuptryingtoreadyourcode.

If you can't be bothered to use spaces to make your code readable, and properly format it, I can't be bothered to read it.

There’s a space in this line:-

if((lastleft>left)&&(lefttimer1<=(millis()-analogRead(droprate)))&&(lefttimer2 <(millis()-20))){

yah sorry about that i did not realize it was that bad but i found what was wrong it was in this code

i was reading 7 pins to get how meany pixels are connected well the pins that are commented out must be able to float up to read high giving a a number other then 14 also is the spacing better on this?

  //pinMode(22,INPUT_PULLUP);
  pinMode(24,INPUT_PULLUP);
  pinMode(26,INPUT_PULLUP);
  pinMode(28,INPUT_PULLUP);
  //pinMode(30,INPUT_PULLUP);
  //pinMode(32,INPUT_PULLUP);
  //pinMode(34,INPUT_PULLUP);
  //pinMode(36,INPUT_PULLUP);
  
  byte readpin = 34;
  for(byte i=0; i < 7; i++){
     
    if(digitalRead(readpin) == true){
    striplength = striplength << 1 | 1;
    }else{
      striplength = striplength << 1 | 0;
    }
     readpin--;
     readpin--;
  }
  //stripleft.setnumpixals(striplength);