Multiple rgb led and switch change

I've posted a few things related to this project but I have one big issue. I have 16 rgb led lights constantly changing color. Each light has a button. When you press a button it turns that strip a solid color. When you press it again I want it to return to the changing of colors. I'm having a hard time figuring out how to set this up so that it can all run without delay. ie. I want to press two buttons at once if possible or at least press a button and not let it affect the cycle of all the other led's? I've gotten it to change to a solid color before, but getting it to change back has been in an issue.

Any ideas would be very helpful. And thanks to everyone who continues to help me!

Here is my code: its clearly still getting put together and I feel like it might be a little excessive so if you have any pointers on how to shorten it up please let me know. Thanks :slight_smile:

#define DEBOUNCE 10

// output pins
int inMin = 2;
int inMax = 49;

//input pins
byte button[16]= {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};
               
#define NUMBUTTONS sizeof(button)

byte buttonpressed[NUMBUTTONS], pressed[NUMBUTTONS];

boolean state[16];

boolean lastState[16];
  
long previousMillis[48];
     
long interval[48] = {500, 600, 550, 500, 600, 550, 500};

long time[48];
 
void setup() { 
  
  byte i;

Serial.begin(9600);  

  for(int i=inMin; i<=inMax; i++)
{
   pinMode(i, OUTPUT);
}   
 
 
 for(i = 0; i< 16; i++)
 {
  pinMode(button[i], INPUT);
  } 


for(int i=0; i<16; i++)
{
   buttonpressed[i] = 0;
}


for(int i=0; i<49; i++)
{
   previousMillis[i] = 0;
}

for(int i=0; i<16; i++)
{
   lastState[i] = LOW;
}

for(int i=0; i<2; i++)
{
  time[i] = millis();
}

}

void check_switches() {
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  static long lasttime;
  byte index;
  
  if (millis() < lasttime){
    lasttime = millis();
} 

  if ((lasttime + DEBOUNCE) > millis()) {
    return;
  }

lasttime = millis();

for (index = 0; index < NUMBUTTONS; index++) {
buttonpressed[index] = 0;

currentstate[index] = digitalRead(button[index]);
if(currentstate[index] == previousstate[index]) {
  
  if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
    
    buttonpressed[index] = 1;
  }
  pressed[index] = !currentstate[index];
}
previousstate[index] = currentstate[index];
}
}


void loop() 
{
  
  check_switches();
 
    if(buttonpressed[0] == 1 && state[0] == 1){
      square1solid();}
    else if (buttonpressed[0] == 0 && state[1] == 0){
     square1(); 
   
   if(buttonpressed[1] == 1 && state[1] == 1){
     square2solid();
 }
     else if (buttonpressed[1] == 0 && state[1] == 0){
       square2();}
      
}
/////////////////////////////////Square 1///////////////////////////////////
}
void square1solid() {
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);}

void square1(){
byte i;
 unsigned long currentMillis1 = millis();
   if (currentMillis1 - time[0] > interval[0]) {
     time[0] = currentMillis1;
     
        if(lastState[0] == LOW)
          lastState[0] = HIGH; 
        else 
          lastState[0] = LOW;
          
          digitalWrite(2, lastState[0]);
   }
       
       
  unsigned long currentMillis2 = millis();
  
   if (currentMillis2 - time[1] > interval[1]) {
     time[1] = currentMillis2;
     
        if(lastState[1] == LOW)
          lastState[1] = HIGH;
          
        else 
          lastState[1] = LOW;
   
          digitalWrite(3, lastState[1]);
    }
    
     unsigned long currentMillis3 = millis();
  
   if (currentMillis3 - time[2] > interval[2]) {
     time[2] = currentMillis3;
     
        if(lastState[2] == LOW)
          lastState[2] = HIGH;
          
        else 
          lastState[2] = LOW;
          
          digitalWrite(4, lastState[2]);
          
   }
}
   
   /////////////////////////Square 2////////////////////////////////
   void square2solid() {
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);}
   
   
   void square2(){
byte i;
 unsigned long currentMillis4 = millis();
   if (currentMillis4 - time[3] > interval[3]) {
     time[3] = currentMillis4;
     
        if(lastState[3] == LOW)
          lastState[3] = HIGH; 
        else 
          lastState[3] = LOW;
          
          digitalWrite(5, lastState[3]);
   }
       
       
  unsigned long currentMillis5 = millis();
  
   if (currentMillis5 - time[4] > interval[4]) {
     time[4] = currentMillis5;
     
        if(lastState[4] == LOW)
          lastState[4] = HIGH;
          
        else 
          lastState[4] = LOW;
   
          digitalWrite(6, lastState[4]);
    }
    
     unsigned long currentMillis6 = millis();
  
   if (currentMillis6 - time[5] > interval[5]) {
     time[5] = currentMillis6;
     
        if(lastState[5] == LOW)
          lastState[5] = HIGH;
          
        else 
          lastState[5] = LOW;
          
          digitalWrite(7, lastState[5]);
          
   }
}

look to advance the state as one block of code then respond to that change with another:

you have:

  check_switches();
 
    if(buttonpressed[0] == 1 && state[0] == 1){
      square1solid();}
    else if (buttonpressed[0] == 0 && state[1] == 0){
     square1(); 
   
   if(buttonpressed[1] == 1 && state[1] == 1){
     square2solid();
 }
     else if (buttonpressed[1] == 0 && state[1] == 0){
       square2();}

try something like:

byte pressed = digitalRead(pushbutton);
if (pressed)
 {
   if (lastPressed != pressed)
   {
     state++;
     if (state > maxStates)
     {
       state = 0;
     }
   }
 }
 lastPressed = pressed;
 if (state == 0)
 {
   //do zero state
 }
 else if  (state == 1)
 {
   // do one state
 }
 else if (...

much simpler than what you are doing there...

Okay cool. Thanks BulldogLowell, I'll give that a try.

BulldogLowell:
look to advance the state as one block of code then respond to that change with another:

you have:

  check_switches();

if(buttonpressed[0] == 1 && state[0] == 1){
      square1solid();}
    else if (buttonpressed[0] == 0 && state[1] == 0){
     square1();
   
   if(buttonpressed[1] == 1 && state[1] == 1){
     square2solid();
}
     else if (buttonpressed[1] == 0 && state[1] == 0){
       square2();}




try something like:



byte pressed = digitalRead(pushbutton);
if (pressed)
{
   if (lastPressed != pressed)
   {
     state++;
     if (state > maxStates)
     {
       state = 0;
     }
   }
}
lastPressed = pressed;
if (state == 0)
{
   //do zero state
}
else if  (state == 1)
{
   // do one state
}
else if (...




much simpler than what you are doing there...

I had it working, and now I can't seem to get it back up and running correctly. The second rgb strip is working perfectly but the first one starts up correctly and then doesn't turn off two colors and blinks the other. I've spent hours trying to figure out why and I can't.

Let me know if you can help.

#define DEBOUNCE 10

// output pins
int inMin = 2;
int inMax = 49;

//input pins
byte button[16]= {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};
               
#define NUMBUTTONS sizeof(button)

byte buttonpressed[NUMBUTTONS], pressed[NUMBUTTONS];

boolean state[16];

boolean lastState[16];
  
long previousMillis[48];
     
long interval[48] = {500, 600, 550, 500, 600, 550, 500};

long time[48];
 
void setup() { 
  
  byte i;

Serial.begin(9600);  

  for(int i=inMin; i<=inMax; i++)
{
   pinMode(i, OUTPUT);
}   
 
 
 for(i = 0; i< 16; i++)
 {
  pinMode(button[i], INPUT);
  } 


for(int i=0; i<16; i++)
{
   buttonpressed[i] = 0;
}


for(int i=0; i<48; i++)
{
   previousMillis[i] = 0;
}

for(int i=0; i<16; i++)
{
   lastState[i] = LOW;
}

for(int i=0; i<48; i++)
{
  time[i] = millis();
}

for(int i=0; i<16; i++)
{
  state[i] = LOW;
}

}

void check_switches() {
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  static long lasttime;
  byte index;
  
  if (millis() < lasttime){
    lasttime = millis();
} 

  if ((lasttime + DEBOUNCE) > millis()) {
    return;
  }

lasttime = millis();

for (index = 0; index < NUMBUTTONS; index++) {
buttonpressed[index] = 0;

currentstate[index] = digitalRead(button[index]);
if(currentstate[index] == previousstate[index]) {
  
  if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
    
    buttonpressed[index] = 1;
  }
  pressed[index] = !currentstate[index];
}
previousstate[index] = currentstate[index];
}
}


void loop() 
{
  
  check_switches();
 
    if(buttonpressed[0])
      {
        if (lastState[0] != buttonpressed[0]) {
          state[0]++;
          if (state[0] > 1)
          {
            state[0] = 0;
          }
        }
      }
      lastState[0] = buttonpressed[0];
      if (state[0] == 0)
      {square1();}
      
      else if (state[0] == 1) {

      square1solid();}
      
   if(buttonpressed[1])
      {
        if (lastState[1] != buttonpressed[1]) {
          state[1]++;
          if (state[1] > 1)
          {
            state[1] = 0;
          }
        }
      }
      lastState[1] = buttonpressed[1];
      if (state[1] == 0)
      {square2();}
      
      else if (state[1] == 1) {

      square2solid();}
     
}




/////////////////////////////////Square 1///////////////////////////////////

void square1solid() {
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);}



void square1(){
  unsigned long currentMillis1 = millis();
   if (currentMillis1 - time[0] > interval[0]) {
     time[0] = currentMillis1;
     
        if(lastState[0] == LOW)
          lastState[0] = HIGH; 
        else 
          lastState[0] = LOW;
          
          digitalWrite(2, lastState[0]);
   }
       
       
  unsigned long currentMillis2 = millis();
  
   if (currentMillis2 - time[1] > interval[1]) {
     time[1] = currentMillis2;
     
        if(lastState[1] == LOW)
          lastState[1] = HIGH;
          
        else 
          lastState[1] = LOW;
   
          digitalWrite(3, lastState[1]);
    }
    
     unsigned long currentMillis3 = millis();
  
   if (currentMillis3 - time[2] > interval[2]) {
     time[2] = currentMillis3;
     
        if(lastState[2] == LOW)
          lastState[2] = HIGH;
          
        else 
          lastState[2] = LOW;
          
          digitalWrite(4, lastState[2]);
          
   }
}
   
   /////////////////////////Square 2////////////////////////////////
void square2solid() {
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);}
   
   
void square2(){
 unsigned long currentMillis4 = millis();
   if (currentMillis4 - time[3] > interval[3]) {
     time[3] = currentMillis4;
     
        if(lastState[3] == LOW)
          lastState[3] = HIGH; 
        else 
          lastState[3] = LOW;
          
          digitalWrite(5, lastState[3]);
   }
       
       
  unsigned long currentMillis5 = millis();
  
   if (currentMillis5 - time[4] > interval[4]) {
     time[4] = currentMillis5;
     
        if(lastState[4] == LOW)
          lastState[4] = HIGH;
          
        else 
          lastState[4] = LOW;
   
          digitalWrite(6, lastState[4]);
    }
    
     unsigned long currentMillis6 = millis();
  
   if (currentMillis6 - time[5] > interval[5]) {
     time[5] = currentMillis6;
     
        if(lastState[5] == LOW)
          lastState[5] = HIGH;
          
        else 
          lastState[5] = LOW;
          
          digitalWrite(7, lastState[5]);
          
   }
}

The stuff in your loop() function doesn't make sense. Why would you first see if the button is high, then see if it changed? If the button is HIGH and there is nothing within that IF statement to say otherwise, then it will always be HIGH.

Try this, Just replace your loop function with this.

void loop() 
{
  check_switches();
  if (lastState[0] != buttonpressed[0])  // check for state change
  {
    if(buttonpressed[0]) // if button state is HIGH, then do something
    {
      state[0]++;
      if (state[0] > 1)
      {
        state[0] = 0;
      }
    }
    lastState[0] = buttonpressed[0]; // update lastState
  }
  if (state[0] == 0)
  {
    square1();
  }

  else if (state[0] == 1)
  {
    square1solid();
  }
  if (lastState[1] != buttonpressed[1]) 
  {
    if(buttonpressed[1])
    {
      state[1]++;
      if (state[1] > 1)
      {
        state[1] = 0;
      }
    }
    lastState[1] = buttonpressed[1];
  }
  if (state[1] == 0)
  {
    square2();
  }

  else if (state[1] == 1) 
  {
    square2solid();
  }
}

I replaced the old loop with the new loop and it's still doing the same thing. I added a third rgb led strip to the code to see if maybe that could help me narrow down the problem.

The third rgb strip works great just like the second, its only the 1st that doesn't work. All three colors on the first strip stay on rather than alternate colors. I tap the button and it goes solid but I have to double tap it to make it leave the square1solid function. :confused:

#define DEBOUNCE 10

// output pins
int inMin = 2;
int inMax = 49;

//input pins
byte button[16]= {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};
               
#define NUMBUTTONS sizeof(button)

byte buttonpressed[NUMBUTTONS], pressed[NUMBUTTONS];

boolean state[16];

boolean lastState[16];
  
long previousMillis[48];
     
long interval[48] = {500, 600, 550, 500, 600, 550, 500, 600, 550};

long time[48];
 
void setup() { 
  
  byte i;

Serial.begin(9600);  

  for(int i=inMin; i<=inMax; i++)
{
   pinMode(i, OUTPUT);
}   
 
 
 for(i = 0; i< 16; i++)
 {
  pinMode(button[i], INPUT);
  } 


for(int i=0; i<16; i++)
{
   buttonpressed[i] = 0;
}


for(int i=0; i<48; i++)
{
   previousMillis[i] = 0;
}

for(int i=0; i<16; i++)
{
   lastState[i] = LOW;
}

for(int i=0; i<48; i++)
{
  time[i] = millis();
}

for(int i=0; i<16; i++)
{
  state[i] = LOW;
}

}

void check_switches() {
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  static long lasttime;
  byte index;
  
  if (millis() < lasttime){
    lasttime = millis();
} 

  if ((lasttime + DEBOUNCE) > millis()) {
    return;
  }

lasttime = millis();

for (index = 0; index < NUMBUTTONS; index++) {
buttonpressed[index] = 0;

currentstate[index] = digitalRead(button[index]);
if(currentstate[index] == previousstate[index]) {
  
  if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
    
    buttonpressed[index] = 1;
  }
  pressed[index] = !currentstate[index];
}
previousstate[index] = currentstate[index];
}
}


void loop() 
{
  
  check_switches();
 
     if (lastState[0] != buttonpressed[0])  // check for state change
  {
    if(buttonpressed[0]) // if button state is HIGH, then do something
    {
      state[0]++;
      if (state[0] > 1)
      {
        state[0] = 0;
      }
    }
    lastState[0] = buttonpressed[0]; // update lastState
  }
  if (state[0] == 0)
  {
    square1();
  }

  else if (state[0] == 1)
  {
    square1solid();
  }
  
  if (lastState[1] != buttonpressed[1]) 
  {
    if(buttonpressed[1])
    {
      state[1]++;
      if (state[1] > 1)
      {
        state[1] = 0;
      }
    }
    lastState[1] = buttonpressed[1];
  }
  if (state[1] == 0)
  {
    square2();
  }

  else if (state[1] == 1) 
  {
    square2solid();
  }
  
      if (lastState[2] != buttonpressed[2])  // check for state change
  {
    if(buttonpressed[2]) // if button state is HIGH, then do something
    {
      state[2]++;
      if (state[2] > 1)
      {
        state[2] = 0;
      }
    }
    lastState[2] = buttonpressed[2]; // update lastState
  }
  if (state[2] == 0)
  {
    square3();
  }

  else if (state[2] == 1)
  {
    square3solid();
  }
}




/////////////////////////////////Square 1///////////////////////////////////

void square1solid() {
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);}



void square1(){
  unsigned long currentMillis1 = millis();
   if (currentMillis1 - time[0] > interval[0]) {
     time[0] = currentMillis1;
     
        if(lastState[0] == LOW)
          lastState[0] = HIGH; 
        else 
          lastState[0] = LOW;
          
          digitalWrite(2, lastState[0]);
   }
       
       
  unsigned long currentMillis2 = millis();
  
   if (currentMillis2 - time[1] > interval[1]) {
     time[1] = currentMillis2;
     
        if(lastState[1] == LOW)
          lastState[1] = HIGH;
          
        else 
          lastState[1] = LOW;
   
          digitalWrite(3, lastState[1]);
    }
    
     unsigned long currentMillis3 = millis();
  
   if (currentMillis3 - time[2] > interval[2]) {
     time[2] = currentMillis3;
     
        if(lastState[2] == LOW)
          lastState[2] = HIGH;
          
        else 
          lastState[2] = LOW;
          
          digitalWrite(4, lastState[2]);
          
   }
}
   
   /////////////////////////Square 2////////////////////////////////
void square2solid() {
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);}
   
   
void square2(){
 unsigned long currentMillis4 = millis();
   if (currentMillis4 - time[3] > interval[3]) {
     time[3] = currentMillis4;
     
        if(lastState[3] == LOW)
          lastState[3] = HIGH; 
        else 
          lastState[3] = LOW;
          
          digitalWrite(5, lastState[3]);
   }
       
       
  unsigned long currentMillis5 = millis();
  
   if (currentMillis5 - time[4] > interval[4]) {
     time[4] = currentMillis5;
     
        if(lastState[4] == LOW)
          lastState[4] = HIGH;
          
        else 
          lastState[4] = LOW;
   
          digitalWrite(6, lastState[4]);
    }
    
     unsigned long currentMillis6 = millis();
  
   if (currentMillis6 - time[5] > interval[5]) {
     time[5] = currentMillis6;
     
        if(lastState[5] == LOW)
          lastState[5] = HIGH;
          
        else 
          lastState[5] = LOW;
          
          digitalWrite(7, lastState[5]);
          
   }
}
      /////////////////////////Square 3////////////////////////////////
void square3solid() {
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);}
   
   
void square3(){
 unsigned long currentMillis7 = millis();
   if (currentMillis7 - time[6] > interval[6]) {
     time[6] = currentMillis7;
     
        if(lastState[6] == LOW)
          lastState[6] = HIGH; 
        else 
          lastState[6] = LOW;
          
          digitalWrite(8, lastState[6]);
   }
       
       
  unsigned long currentMillis8 = millis();
  
   if (currentMillis8 - time[7] > interval[7]) {
     time[7] = currentMillis8;
     
        if(lastState[7] == LOW)
          lastState[7] = HIGH;
          
        else 
          lastState[7] = LOW;
   
          digitalWrite(9, lastState[7]);
    }
    
     unsigned long currentMillis9 = millis();
  
   if (currentMillis9 - time[8] > interval[8]) {
     time[8] = currentMillis9;
     
        if(lastState[8] == LOW)
          lastState[8] = HIGH;
          
        else 
          lastState[8] = LOW;
          
          digitalWrite(10, lastState[8]);
          
   }
}

Try this code, If there is no difference, please post pictures or a video.

#define DEBOUNCE 10

// output pins
int inMin = 2;
int inMax = 49;

//input pins
byte button[16]= {
  A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};

#define NUMBUTTONS sizeof(button)

boolean buttonpressed[NUMBUTTONS], pressed[NUMBUTTONS];
boolean previousstate[NUMBUTTONS];
boolean currentstate[NUMBUTTONS];

boolean state[16];

boolean lastState[16];

long previousMillis[48];

long interval[48] = {
  500, 600, 550, 500, 600, 550, 500, 600, 550};

long time[48];
long lasttime;

void setup() 
{ 
  Serial.begin(9600);  

  for(int i=inMin; i <= inMax; i++)
  {
    pinMode(i, OUTPUT);
  }   

  for(i = 0; i< 16; i++)
  {
    pinMode(button[i], INPUT);
    buttonpressed[i] = 0;
    lastState[i] = LOW;
    state[i] = LOW;
  } 

  for(int i=0; i<48; i++)
  {
    previousMillis[i] = 0;
    time[i] = millis();
  }
}

void check_switches() 
{
  byte index;

  if (millis() - lasttime < DEBOUNCE)
  {
    lasttime = millis();
    return;
  }
  else 
    lasttime = millis();

  for (index = 0; index < NUMBUTTONS; index++) 
  {
    buttonpressed[index] = 0;

    currentstate[index] = digitalRead(button[index]);
    if(currentstate[index] != previousstate[index]) 
    {
      previousstate[index] = currentstate[index];
      if(currentstate[index] == HIGH) 
      {
        buttonpressed[index] = 1;
      }
    }
  }
}


void loop() 
{
  check_switches();

  if (lastState[0] != buttonpressed[0])  // check for state change
  {
    if(buttonpressed[0]) // if button state is HIGH, then do something
    {
      state[0]++;
      if (state[0] > 1)
      {
        state[0] = 0;
      }
    }
    lastState[0] = buttonpressed[0]; // update lastState
  }
  if (state[0] == 0)
  {
    square1();
  }

  else if (state[0] == 1)
  {
    square1solid();
  }

  if (lastState[1] != buttonpressed[1]) 
  {
    if(buttonpressed[1])
    {
      state[1]++;
      if (state[1] > 1)
      {
        state[1] = 0;
      }
    }
    lastState[1] = buttonpressed[1];
  }
  if (state[1] == 0)
  {
    square2();
  }

  else if (state[1] == 1) 
  {
    square2solid();
  }

  if (lastState[2] != buttonpressed[2])  // check for state change
  {
    if(buttonpressed[2]) // if button state is HIGH, then do something
    {
      state[2]++;
      if (state[2] > 1)
      {
        state[2] = 0;
      }
    }
    lastState[2] = buttonpressed[2]; // update lastState
  }
  if (state[2] == 0)
  {
    square3();
  }

  else if (state[2] == 1)
  {
    square3solid();
  }
}




/////////////////////////////////Square 1///////////////////////////////////

void square1solid() 
{
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
}

void square1()
{
  unsigned long currentMillis1 = millis();
  if (currentMillis1 - time[0] > interval[0]) 
  {
    time[0] = currentMillis1;
    lastState[0] = !lastState[0];
    digitalWrite(2, lastState[0]);
  }

  unsigned long currentMillis2 = millis();
  if (currentMillis2 - time[1] > interval[1]) 
  {
    time[1] = currentMillis2;
    lastState[1] = !lastState[1];
    digitalWrite(3, lastState[1]);
  }

  unsigned long currentMillis3 = millis();
  if (currentMillis3 - time[2] > interval[2])
  {
    time[2] = currentMillis3;
    lastState[2] = !lastState[2];
    digitalWrite(4, lastState[2]);
  }
}

/////////////////////////Square 2////////////////////////////////
void square2solid() 
{
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
}


void square2()
{
  unsigned long currentMillis4 = millis();
  if (currentMillis4 - time[3] > interval[3]) 
  {
    time[3] = currentMillis4;
    lastState[3] = !lastState[3];
    digitalWrite(5, lastState[3]);
  }

  unsigned long currentMillis5 = millis();

  if (currentMillis5 - time[4] > interval[4]) 
  {
    time[4] = currentMillis5;
    lastState[4] = !lastState[4];
    digitalWrite(6, lastState[4]);
  }

  unsigned long currentMillis6 = millis();

  if (currentMillis6 - time[5] > interval[5]) 
  {
    time[5] = currentMillis6;
    lastState[5] = !lastState[5];
    digitalWrite(7, lastState[5]);
  }
}
/////////////////////////Square 3////////////////////////////////
void square3solid() 
{
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
}

void square3()
{
  unsigned long currentMillis7 = millis();
  if (currentMillis7 - time[6] > interval[6])
  {
    time[6] = currentMillis7;
    lastState[6] = !lastState[6];
    digitalWrite(8, lastState[6]);
  }

  unsigned long currentMillis8 = millis();

  if (currentMillis8 - time[7] > interval[7]) 
  {
    time[7] = currentMillis8;
    lastState[7] = !lastState[7];
    digitalWrite(9, lastState[7]);
  }

  unsigned long currentMillis9 = millis();

  if (currentMillis9 - time[8] > interval[8]) 
  {
    time[8] = currentMillis9;
    lastState[8] = !lastState[8];
    digitalWrite(10, lastState[8]);
  }
}

The last code you sent me prevented the buttons from working. I took a video of the project running from the code prior and attached it.

I had this working at one time and I have no idea what I changed to prevent the first strip from working.
There's an rgb strip in each square. Each square is changing except for the first one. When I touch it (which initiates the button), it goes solid red. But I have to double tap it to get it out of solid function. So I guess its kind of two issues I need to address.

Thank you for your help.

IMG_1060.MOV (1.62 MB)

I might have the operator in this backwards.

if (millis() - lasttime < DEBOUNCE)
{
lasttime = millis();
return;
}
else
lasttime = millis();

I can't test your code until I get home at 6pm.

I think I figured it out. I've posted my new code and everything seems to work.
Please correct me if I'm wrong. I was calling lastState[] in the loop and in my functions, I think this may have been the issue? When I created another array oldState[] and replaced lastState[] in my loop with it, everything started working.

#define DEBOUNCE 10

// output pins
int inMin = 2;
int inMax = 49;

//input pins
byte button[16]= {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};
               
#define NUMBUTTONS sizeof(button)

byte buttonpressed[NUMBUTTONS], pressed[NUMBUTTONS];

boolean state[16];

boolean lastState[16];
boolean oldState[16];
  
long previousMillis[48];
     
long interval[48] = {500, 600, 550, 500, 600, 550, 500, 600, 550};

long time[48];
 
void setup() { 
  
  byte i;

Serial.begin(9600);  

  for(int i=inMin; i<inMax; i++)
{
   pinMode(i, OUTPUT);
}   

for(int i=0; i<16; i++)
{
   buttonpressed[i] = 0;
   state[i] = LOW;
   lastState[i] = LOW;
   pinMode(button[i], INPUT);
   oldState[i] = LOW;
}


for(int i=0; i<48; i++)
{
   previousMillis[i] = 0;
   time[i] = millis();
}

}

void check_switches() {
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  static long lasttime;
  byte index;
  
  if (millis() < lasttime){
    lasttime = millis();
} 

  if ((lasttime + DEBOUNCE) > millis()) {
    return;
  }

lasttime = millis();

for (index = 0; index < NUMBUTTONS; index++) {
buttonpressed[index] = 0;

currentstate[index] = digitalRead(button[index]);
if(currentstate[index] == previousstate[index]) {
  
  if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
    
    buttonpressed[index] = 1;
  }
  pressed[index] = !currentstate[index];
}
previousstate[index] = currentstate[index];
}
}


void loop() 
{
  
  check_switches();
 
     if (oldState[0] != buttonpressed[0])  // check for state change
  {
    if(buttonpressed[0]) // if button state is HIGH, then do something
    {
      state[0]++;
      if (state[0] > 1)
      {
        state[0] = 0;
      }
    }
    oldState[0] = buttonpressed[0]; // update lastState
  }
  if (state[0] == 0)
  {
    square1();
  }

  else if (state[0] == 1)
  {
    square1solid();
  }
  
  if (oldState[1] != buttonpressed[1]) 
  {
    if(buttonpressed[1])
    {
      state[1]++;
      if (state[1] > 1)
      {
        state[1] = 0;
      }
    }
    oldState[1] = buttonpressed[1];
  }
  if (state[1] == 0)
  {
    square2();
  }

  else if (state[1] == 1) 
  {
    square2solid();
  }
  
      if (oldState[2] != buttonpressed[2])  // check for state change
  {
    if(buttonpressed[2]) // if button state is HIGH, then do something
    {
      state[2]++;
      if (state[2] > 1)
      {
        state[2] = 0;
      }
    }
    oldState[2] = buttonpressed[2]; // update lastState
  }
  if (state[2] == 0)
  {
    square3();
  }

  else if (state[2] == 1)
  {
    square3solid();
  }
}




/////////////////////////////////Square 1///////////////////////////////////

void square1solid() {
  digitalWrite(2, HIGH);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);}



void square1(){
  unsigned long currentMillis1 = millis();
   if (currentMillis1 - time[0] > interval[0]) {
     time[0] = currentMillis1;
     
        if(lastState[0] == LOW)
          lastState[0] = HIGH; 
        else 
          lastState[0] = LOW;
          
          digitalWrite(2, lastState[0]);
   }
       
       
  unsigned long currentMillis2 = millis();
  
   if (currentMillis2 - time[1] > interval[1]) {
     time[1] = currentMillis2;
     
        if(lastState[1] == LOW)
          lastState[1] = HIGH;
          
        else 
          lastState[1] = LOW;
   
          digitalWrite(3, lastState[1]);
    }
    
     unsigned long currentMillis3 = millis();
  
   if (currentMillis3 - time[2] > interval[2]) {
     time[2] = currentMillis3;
     
        if(lastState[2] == LOW)
          lastState[2] = HIGH;
          
        else 
          lastState[2] = LOW;
          
          digitalWrite(4, lastState[2]);
          
   }
}
   
   /////////////////////////Square 2////////////////////////////////
void square2solid() {
  digitalWrite(5, HIGH);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);}
   
   
void square2(){
 unsigned long currentMillis4 = millis();
   if (currentMillis4 - time[3] > interval[3]) {
     time[3] = currentMillis4;
     
        if(lastState[3] == LOW)
          lastState[3] = HIGH; 
        else 
          lastState[3] = LOW;
          
          digitalWrite(5, lastState[3]);
   }
       
       
  unsigned long currentMillis5 = millis();
  
   if (currentMillis5 - time[4] > interval[4]) {
     time[4] = currentMillis5;
     
        if(lastState[4] == LOW)
          lastState[4] = HIGH;
          
        else 
          lastState[4] = LOW;
   
          digitalWrite(6, lastState[4]);
    }
    
     unsigned long currentMillis6 = millis();
  
   if (currentMillis6 - time[5] > interval[5]) {
     time[5] = currentMillis6;
     
        if(lastState[5] == LOW)
          lastState[5] = HIGH;
          
        else 
          lastState[5] = LOW;
          
          digitalWrite(7, lastState[5]);
          
   }
}
      /////////////////////////Square 3////////////////////////////////
void square3solid() {
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);}
   
   
void square3(){
 unsigned long currentMillis7 = millis();
   if (currentMillis7 - time[6] > interval[6]) {
     time[6] = currentMillis7;
     
        if(lastState[6] == LOW)
          lastState[6] = HIGH; 
        else 
          lastState[6] = LOW;
          
          digitalWrite(8, lastState[6]);
   }
       
       
  unsigned long currentMillis8 = millis();
  
   if (currentMillis8 - time[7] > interval[7]) {
     time[7] = currentMillis8;
     
        if(lastState[7] == LOW)
          lastState[7] = HIGH;
          
        else 
          lastState[7] = LOW;
   
          digitalWrite(9, lastState[7]);
    }
    
     unsigned long currentMillis9 = millis();
  
   if (currentMillis9 - time[8] > interval[8]) {
     time[8] = currentMillis9;
     
        if(lastState[8] == LOW)
          lastState[8] = HIGH;
          
        else 
          lastState[8] = LOW;
          
          digitalWrite(10, lastState[8]);
          
   }
}