rgb led multiplexing problem

I'll try to explain this. I'm using a attiny44 with 4 common anode RGB LED's. 3 pwm pins on the attiny44 are being used on common cathodes R,G and B pins. I'm having a problem with the code. I'm trying to have 10 "modes." The syncPin, or button is pressed, the counter is increased by one. When it goes through the mode 2 and 10 it skips over it with a small delay. The LED's flashes quickly. The other modes are fine, but I cannot get the modes 2 and 10 to work. Basically, I guess :confused: its only looping once through mode 2. Something is causing the counter to increase at the end of the loop for mode 2 and 10???

Any and all help would be greatly appreciated.

I'm sure I did not give some crucial information to the project...

ALRIGHT, Thanks!!!!

-Twiener

int redPin = 6; 
int bluePin = 8;
int greenPin = 7; 
int xButton = 3;
int aButton = 1;
int yButton = 2;
int bButton = 4; 

int syncPin = A5;

unsigned int counter;

 





int sensorValue;

int firstCount = 250;
int secondCount = 250;
int thirdCount = 250;
int fourthCount =250;






void setup()

{
  pinMode(redPin, OUTPUT);    // sets the redPin to be an output
  pinMode(greenPin, OUTPUT);    // sets the greenPin to be an output
  pinMode(bluePin, OUTPUT);    // sets the bluePin to be an output
  pinMode(yButton, OUTPUT);
  pinMode(aButton, OUTPUT);
  pinMode(bButton, OUTPUT);
  pinMode(xButton, OUTPUT);
  pinMode(syncPin, INPUT);
  int counter = 1;
}

void loop()

{
  //change mode

  if (counter == 1)
  {

    color(0, 0, 0); //        OFF

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);

    delay(1);

  }
  if (counter == 7)
  {

    color(0, 255, 50); //alien green

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);

    delay(1);

  }



  if(counter == 8)

  {
    color(255,51,153);                     //pink

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);

    delay(1);

  }

  if(counter == 9)
  {
    color(128,0,255);                    //purple
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);   
    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    delay(1);

  }

  if(counter == 5)
  
  {
    color(0,0,255);                                                           // dark blue

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);
    delay(1);
  }

  if(counter == 6)
  
  {
    color(0,255,255);               //light blue

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);
    delay(1);
  }

  if(counter == 4)
  
  {
    color(0,255,0);                   //green

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);
    delay(1);
  }

  if(counter == 11 )
  
  {
    color(255,255,255);                   //WHITE

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);
    delay(1);
  }

  if(counter == 3)
  
  {
    
    color(255,255,0);                   //red

    digitalWrite(yButton, HIGH);
    digitalWrite(xButton, HIGH);
    digitalWrite(bButton, HIGH);
    digitalWrite(aButton, HIGH);
    delay(1);
  }

  if(counter == 2)
  
    {
      
      color(255, 255, 0);

      digitalWrite(yButton, HIGH);
      delayMicroseconds(200);
      
      digitalWrite(yButton, LOW);
      
      color(0, 0 , 255 );
      
      
      
      digitalWrite(xButton, HIGH);
      delayMicroseconds(200);
      
      digitalWrite(xButton, LOW);
            
      color(255, 0, 0);
      
      
      
      digitalWrite(bButton, HIGH);
      delayMicroseconds(200);
      
      digitalWrite(bButton, LOW);
                  
      color(0, 255, 0);
      
      
      
      digitalWrite(aButton, HIGH);
      delayMicroseconds(200);
      
      digitalWrite(aButton, LOW);
      delay(1);
      
    }
      
  if(firstCount > 0 && counter == 10)
  
  {

    {
      color(255, 255, 0);                   //first part
      digitalWrite(yButton, HIGH);
      delay(1);
      digitalWrite(yButton, LOW);

      color(0, 0 , 255 );
      digitalWrite(xButton, HIGH);
      delay(1);
      digitalWrite(xButton, LOW);

      color(255, 0, 0);
      digitalWrite(bButton, HIGH);
      delay(1);
      digitalWrite(bButton, LOW);

      color(0, 255, 0);
      digitalWrite(aButton, HIGH);
      delay(1);
      digitalWrite(aButton, LOW);
      
    }
    firstCount--;
  }




  if(secondCount > 0 && firstCount <= 0 && counter == 10)
  {
    {
      color(0, 255, 0);                 // second part
      digitalWrite(yButton, HIGH);
      delay(1);
      digitalWrite(yButton, LOW);

      color(255, 255, 0);
      digitalWrite(xButton, HIGH);
      delay(1);
      digitalWrite(xButton, LOW);

      color(0, 0 , 255 );
      digitalWrite(bButton, HIGH);
      delay(1);
      digitalWrite(bButton, LOW);

      color(255, 0, 0);
      digitalWrite(aButton, HIGH);
      delay(1);
      digitalWrite(aButton, LOW);
    }
    secondCount--;
  }



  if(thirdCount > 0 && secondCount <= 0 && firstCount <= 0 && counter == 10)
  {
    {
      color(255, 0, 0);                 // third part
      digitalWrite(yButton, HIGH);
      delay(1);
      digitalWrite(yButton, LOW);

      color(0, 255, 0);
      digitalWrite(xButton, HIGH);
      delay(1);
      digitalWrite(xButton, LOW);

      color(255, 255, 0);
      digitalWrite(bButton, HIGH);
      delay(1);
      digitalWrite(bButton, LOW);

      color(0, 0 , 255 );
      digitalWrite(aButton, HIGH);
      delay(1);
      digitalWrite(aButton, LOW);
    }
    thirdCount--;
  }

  if(fourthCount > 0 && thirdCount <= 0 && secondCount <= 0 && firstCount <= 0 && counter == 10)

  {
    {
      color(0, 0, 255);                 // fourth part
      digitalWrite(yButton, HIGH);
      delay(1);
      digitalWrite(yButton, LOW);

      color(255, 0, 0);
      digitalWrite(xButton, HIGH);
      delay(1);
      digitalWrite(xButton, LOW);

      color(0, 255, 0);
      digitalWrite(bButton, HIGH);
      delay(1);
      digitalWrite(bButton, LOW);

      color(255, 255, 0);
      digitalWrite(aButton, HIGH);
      delay(1);
      digitalWrite(aButton, LOW);
    }
    fourthCount--;
  }

  if(fourthCount <=0 && counter == 10)
  {
    firstCount = 250;
    secondCount = 250;
    thirdCount = 250;
    fourthCount = 250;
  }

  

  {
    int sensorValue = analogRead(syncPin);

    float voltage = sensorValue * (5.0 / 1023.0); 

    if(analogRead(sensorValue) < 5)
    {
      delay(200);
      counter ++;
      delay(200); 
    }

//Reset count if over max mode number

    if(counter > 11)
    {
      counter = 1;
    }


  }




} //end loop



void color(unsigned char red, unsigned char green, unsigned char blue)     // the color generating function

{

  analogWrite(bluePin, 255-blue);

  analogWrite(greenPin, 255-green);

  analogWrite(redPin, 255-red);

}

Did you read this?

Why not?

where should i post it?

It's not the "where?" it's the "how many times?".

Don't worry, I deleted the duplicate.

I tried deleting the first one before I posted this one. This is my first time posting sorry, I guess I should have thought harder

All your code?