Controlling an LED Strobe Bar.

Hello All,

I’m trying to control a LED Strobe bar(picture Attached).
As you can see in the picture there’s 4 cables solder to the LED board.
These 4 cables control either the Amber or White side of the LEDs.
I’ve traced the cable points to PIN 5 of the LED drivers IC (BM0550HV).

I wrote this code up to control each color of the strobe.
everything seemed to work but now when I try to control the Amber side, my arduino Uno resets itself.

1 button to turn all amber LEDs on.
1 button to turn all white LEDs on.
1 button to turn all amber LEDs to strobes on.
1 button to turn all white LEDs to strobe on.
1 button to turn on different strobing patterns.

The only issue I’m encountering is that when pressing through the patterns I sometimes have to press the buttom more than once to switch to the next pattern

I’ve added my code and a fritzing design of how I wired the UNO with my breadboard.

const int buttonPin0 = 2;  //Solid All Yellow LEDs   
const int buttonPin1 = 3;  //Solid All White LEDs   
const int buttonPin2 = 4;  //Strobe All Yellow LEDs  
const int buttonPin3 = 5;  //Strobe All White LEDs
const int buttonPin4 = 6;  //Strobe Patterns 
const int ledPin0 =  9;   //First set of Yellow LEDs     
const int ledPin1 =  10;  //First set of White LEDs    
const int ledPin2 =  11;  //Second set of Yellow LEDs   
const int ledPin3 =  12;  //Second set of White LEDs   


int buttonState0 = 0;        
int buttonState1 = 0;         
int buttonState2 = 0;       
int buttonState3 = 0; 

int oldState;
int buttonState4 = 0; 
int state = 0;

unsigned long startTime;
unsigned long interval = 1000UL;

void setup() {
  pinMode(ledPin0, OUTPUT);   
  pinMode(ledPin1, OUTPUT);   
  pinMode(ledPin2, OUTPUT);   
  pinMode(ledPin3, OUTPUT);   

  pinMode(buttonPin0, INPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);  

}

void loop(){
  buttonState0 = digitalRead(buttonPin0);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);

  if (buttonState0 == HIGH) {     //Solid Yellow
    SolidYellow();
  }   
  if (buttonState1 == HIGH) {     // Solid White
    SolidWhite(); 
  }
  if (buttonState2 == HIGH) {     //strobe yellow
    FlashYellow();
  }
  if (buttonState3 == HIGH) {   //strobe white  
    FlashWhite();
  }

  int buttonState4 = digitalRead(buttonPin4);
  {
    if (buttonState4 == HIGH)
    {
      if (oldState == LOW)
      {
        state++;
       if (state > 12) state = 0;
      }
    }
  }
  oldState = buttonState4;
  if (state == 0)
  {
    noFlash();
  }
  else if (state == 1)
  {
    flashA();
  }
  else if (state == 2)
  {
    flashB();
  }
  else if (state == 3)
  {
    flashC();
  }
  else if (state == 4)
  {
    flashD();
  }
  else if (state == 5)
  {
    flashE();
  }
  else if (state == 6)
  {
    flashF();
  }
  else if (state == 7)
  {
    flashG();
  }
  else if (state == 8)
  {
    flashH();
  }
  else if (state == 9)
  {
    flashI();
  }
  else if (state == 10)
  {
    flashJ();
  }
  else if (state == 11)
  {
    flashK();
  }
  else if (state == 12)
  {
    flashL();
  }
}

void FlashYellow()
{
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);   
  delay(100);               
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW);   
  delay(100);               
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);  
  delay(100);               
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW); 
  delay(100);             
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);
  delay(100);
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW); 
  delay(100);
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);
  delay(100);             
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW);   
  delay(100);
}

void FlashWhite()
{
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);   
  delay(100);               
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW);   
  delay(100);               
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);  
  delay(100);               
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW); 
  delay(100);             
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);
  delay(100);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW); 
  delay(100);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);
  delay(100);             
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW);   
  delay(100);
}
void noFlash()
{
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, LOW);
}

//
void flashA() //slow flash Yellow
{
  if (millis() - startTime >= interval)
  {
    digitalWrite(ledPin0, !digitalRead(ledPin0)); 
    digitalWrite(ledPin2, !digitalRead(ledPin2));
    startTime = millis();
  }
}
//
void flashB() //slow flash White
{
  if (millis() - startTime >= interval)
  {
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin2, LOW);
    
    digitalWrite(ledPin1, !digitalRead(ledPin1));
    digitalWrite(ledPin3, !digitalRead(ledPin3));
    startTime = millis();
  }
}
void flashC() //med flash Yellow
{
  if (millis() - startTime >= interval/5UL)
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin3, LOW);
    
    digitalWrite(ledPin0, !digitalRead(ledPin0));
    digitalWrite(ledPin2, !digitalRead(ledPin2));
    startTime = millis();
  }
}
void flashD() //med flash White
{
  if (millis() - startTime >= interval/5UL)
  {
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin2, LOW);
    
    digitalWrite(ledPin1, !digitalRead(ledPin1));
    digitalWrite(ledPin3, !digitalRead(ledPin3));
    startTime = millis();
  }
}
//
void flashE() //fast flash Yellow
{
  if (millis() - startTime >= interval/15UL)
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin3, LOW);
    
    digitalWrite(ledPin0, !digitalRead(ledPin0));
    digitalWrite(ledPin2, !digitalRead(ledPin2));
    startTime = millis();
  }
}
void flashF() //fast flash White
{
  if (millis() - startTime >= interval/15UL)
  {
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin2, LOW);
    
    digitalWrite(ledPin1, !digitalRead(ledPin1));
    digitalWrite(ledPin3, !digitalRead(ledPin3));
    startTime = millis();
  }
}

void flashG() //Weedwacker Yellow Med
{
  if (millis() - startTime >= interval/5UL)
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin3, LOW);
    
    digitalWrite(ledPin0, HIGH);
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin0, HIGH); 
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin0, HIGH); 
    delay(100);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin2, LOW); 
    digitalWrite(ledPin2, HIGH); 
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin2, HIGH); 
    delay(100);   
    
    digitalWrite(ledPin0, LOW);
    delay(50);
    digitalWrite(ledPin2, LOW);     
    delay(50); 
    startTime = millis();
  }
}

void flashH() //Weedwacker White Med
{
  if (millis() - startTime >= interval/5UL)
  {
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin2, LOW);
    
    digitalWrite(ledPin1, HIGH);
    delay(50);
    digitalWrite(ledPin1, LOW);
    delay(50);
    digitalWrite(ledPin1, HIGH);
    delay(50);
    digitalWrite(ledPin1, LOW);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    delay(50);
    digitalWrite(ledPin3, LOW);
    delay(50);
    digitalWrite(ledPin3, HIGH);
    delay(50);
    digitalWrite(ledPin3, LOW);
    delay(100);  
    startTime = millis();
  }
}

void flashI() //Weedwacker Yellow Fast
{
  if (millis() - startTime >= interval/15UL)
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin3, LOW);
    
    digitalWrite(ledPin0, HIGH);
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin0, HIGH); 
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin0, HIGH); 
    delay(100);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin2, LOW); 
    digitalWrite(ledPin2, HIGH); 
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin2, HIGH); 
    delay(100);  
    
    digitalWrite(ledPin0, LOW);
    delay(50);
    digitalWrite(ledPin2, LOW);     
    delay(50); 
    startTime = millis();
  }
}

void flashJ() //Weedwacker White Fast
{
  if (millis() - startTime >= interval/15UL)
  {
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin2, LOW);
    
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin1, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin3, HIGH);
    delay(100);  
    
    digitalWrite(ledPin1, LOW);
    delay(50);
    digitalWrite(ledPin3, LOW);     
    delay(50); 
    startTime = millis();
  }
}
void flashK() //Weedwacker Yellow Faster
{
  if (millis() - startTime >= interval/35UL)
  {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin3, LOW);
    
    digitalWrite(ledPin0, HIGH);
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin0, HIGH); 
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin0, HIGH); 
    delay(100);
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin2, LOW); 
    digitalWrite(ledPin2, HIGH); 
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin2, HIGH); 
    delay(100);  
    
    digitalWrite(ledPin0, LOW);
    delay(100);
    digitalWrite(ledPin2, LOW);     
    delay(50); 
    startTime = millis();
  }
}

void flashL() //Weedwacker White Faster
{
  if (millis() - startTime >= interval/35UL)
  {
    digitalWrite(ledPin0, LOW);
    digitalWrite(ledPin2, LOW);
    
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin1, HIGH);
    delay(100);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin3, HIGH);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin3, HIGH);
    delay(100);       
    
    digitalWrite(ledPin1, LOW);
    delay(50);
    digitalWrite(ledPin3, LOW);     
    delay(50); 
    startTime = millis();
  }
}
void SolidYellow()
{
  // turn LED on: 
  digitalWrite(ledPin0, HIGH);  
  digitalWrite(ledPin2, HIGH); 
  // turn LED off:
  digitalWrite(ledPin0, LOW); 
  digitalWrite(ledPin2, LOW); 
}

void SolidWhite()
{
  // turn LED on:    
  digitalWrite(ledPin1, HIGH);  
  digitalWrite(ledPin3, HIGH); 
  // turn LED off:
  digitalWrite(ledPin1, LOW); 
  digitalWrite(ledPin3, LOW);  
}
 int buttonState4 = digitalRead(buttonPin4);
  {
    if (buttonState4 == HIGH)
    {
      if (oldState == LOW)
      {
        state++;
        if (state > 12) state = 0;
      }
    }
  }

This part of code has fault. You not set default state of oldstate i.e low or High.

So I wrote this code up to control each color of the strobe.
everything seemed to work but now when I try to control the Amber side, my arduino Uno resets itself.

What does it means???

I want to be able to do the following:

1 button to turn all amber LEDs on.
1 button to turn all white LEDs on.
1 button to turn all amber LEDs to strobe on.
1 button to turn all white LEDs to strobe on.
1 button to turn on different strobing patterns.

But when I press the amber LEDs to Strobe on, it no strobe as desired. It looks like the arduino resets or reboots. This also happens if I press the strobe pattern buttons, the amber led strobing patterns will cause the same issue to my arduino.

The odd thing is that when I remove 1 of the amber wires from my arduino the amber strobing works but only on one side of the LED Bar.

The voltage is the same as the white LEDs.

Steve

Can you tell me the you wanted to operated below function

1 button to turn all amber LEDs on.
1 button to turn all white LEDs on.
1 button to turn all amber LEDs to strobe on.
1 button to turn all white LEDs to strobe on.
1 button to turn on different strobing patterns.

Which are those button???

what does it means.MY English is bad. so can you explain in simple words??

But when I press the amber LEDs to Strobe on, it no strobe as desired

AMPS-N:
Can you tell me the you wanted to operated below function

2 on-off-on center off toggle switches and 1 pushbutton

First Toggle Switch Should do:
flip Toggle Switch up turn all amber LEDs on. = buttonPin0
flip Toggle Switch down all white LEDs on. = buttonPin1

Second Toggle Switch Should do:
flip Toggle Switch up all amber LEDs to strobe on. = buttonPin2
flip Toggle Switch down all white LEDs to strobe on. =buttonPin3

also if the second toggle switch are turned on (either up of down)

1 pushbutton to turn should switch between different strobing patterns. = buttonPin4

I can't seem to get the toggle on and pushbutton working together.

Thanks,

Steve

Can you put schematic of connection diagram & also share me datasheet of toggle switch

Intially i thought it just DIP /pushbutton switches which is having 2 state

By seeing you statement 0n-off-on

here also 2 state but you can do other functionality like spst,DPDT switches.

I’ve attached the fritzing drawing below.

Pins 9-12 go to the strobe light bars 4 cables which trigger the color you would like to use.

you can see in the picture of the strobe light bar where there is 4 cables soldered to the Trigger for each color of the LED bar.

The toggle switches are just normal SPDT type switches.

You havent understand my question. What kind of toggle switch you are using

When you say ON-OFF-ON Switch, like in that image attached or different one.

If it same you should use 2 diffent pins to read their status.

on-off-on.jpg

const int buttonPin0 = 2;  //Solid All Yellow LEDs   
const int buttonPin1 = 3;  //Solid All White LEDs   
const int buttonPin2 = 4;  //Strobe All Yellow LEDs  
const int buttonPin3 = 5;  //Strobe All White LEDs
const int buttonPin4 = 6;  //Strobe Patterns 
const int ledPin0 =  9;   //First set of Yellow LEDs     
const int ledPin1 =  10;  //First set of White LEDs    
const int ledPin2 =  11;  //Second set of Yellow LEDs   
const int ledPin3 =  12;  //Second set of White LEDs   


int buttonState0 = 0;        
int buttonState1 = 0;         
int buttonState2 = 0;       
int buttonState3 = 0; 

int oldState=0;
int buttonState4 = 0; 
static int state = 0;

unsigned long startTime;
unsigned long interval = 1000UL;

void setup() {
  pinMode(ledPin0, OUTPUT);   
  pinMode(ledPin1, OUTPUT);   
  pinMode(ledPin2, OUTPUT);   
  pinMode(ledPin3, OUTPUT);   

  pinMode(buttonPin0, INPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);  
Serial.begin(9600);
}

void loop(){
  buttonState0 = digitalRead(buttonPin0);// turn on all yellow LED
  buttonState1 = digitalRead(buttonPin1);// turn on all white LED
  buttonState2 = digitalRead(buttonPin2);// turn on all Strobe_yellow LED
   buttonState3 = digitalRead(buttonPin3);// turn on all strobe_white_LED
  buttonState4 = digitalRead(buttonPin4);// turn on alternate

  if (buttonState0 == HIGH) {     //Solid Yellow
    SolidYellow();
  } 
  
  if (buttonState1 == HIGH) {     // Solid White
    SolidWhite(); 
  }
  if((buttonState0 ==LOW )&& (buttonState1 == LOW))
  {
    Turn_OFF_Solid();
  }
  
  
  if (buttonState2 == HIGH) {     //strobe yellow
    FlashYellow();
  }
  if (buttonState3 == HIGH) {   //strobe white  
    FlashWhite();
  }
  
   if((buttonState2 ==LOW )&& (buttonState3 == LOW))
  {
    Turn_OFF_strobe();
  }
  
  

  int buttonState4 = digitalRead(buttonPin4);
  {
    if (buttonState4 == HIGH)
    {
      if (oldState == LOW)
      {
        state++;
        
        Serial.print("state:");Serial.println(state);
        if (state > 12) state = 0;
      }
    }
  }
  oldState = buttonState4;
  if (state == 0)
  {
    noFlash();Serial.println("noflash");
  }
  else if (state == 1)
  {
    flashA();Serial.println("flashA");
  }
  else if (state == 2)
  {
    flashB();Serial.println("flash B");
  }
  else if (state == 3)
  {
    flashC();Serial.println("flash c");
  }
  else if (state == 4)
  {
    flashD();Serial.println("flash d");
  }
  else if (state == 5)
  {
    flashE();Serial.println("flash E");
  }
  else if (state == 6)
  {
    flashF();Serial.println("flash F");
  }
  else if (state == 7)
  {
    flashG();Serial.println("flash G");
  }
  else if (state == 8)
  {
    flashH();Serial.println("flash H");
  }
  else if (state == 9)
  {
    flashI();Serial.println("flash I");
  }
  else if (state == 10)
  {
    flashJ();Serial.println("flash J");
  }
  else if (state == 11)
  {
    flashK();Serial.println("flash K");
  }
  else if (state == 12)
  {
    flashL();Serial.println("flash L");
  }
  
  delay(1000);
  Serial.println(".................................");
  
  
}





void  Turn_OFF_Solid()
{
 digitalWrite(ledPin0, LOW); 
 digitalWrite(ledPin2, LOW); 
  // turn LED off:
 digitalWrite(ledPin1, LOW); 
  digitalWrite(ledPin3, LOW); 
}


void  Turn_OFF_strobe()
{
 Serial.println("turn off ");
  
}




void SolidYellow()
{
  // turn LED on: 
  digitalWrite(ledPin0, HIGH);  
  digitalWrite(ledPin2, HIGH); 
  // turn LED off:
  
}

void SolidWhite()
{
  // turn LED on:    
  digitalWrite(ledPin1, HIGH);  
  digitalWrite(ledPin3, HIGH); 
   
}

Since i have check your code. I altered some part..

But i need what is function of each function . what you expected do

void FlashWhite()
{
// what you are trying to do here??
}

void FlashYellow()

{
// what you are trying to do here

}

because you are doing setting led on off improper ways.I could understand functionality of doing it. code wise ok. after uploading my code what problem you are facing???

FlashYellow() and FlashWhite() do the following, but i will have this changed for what I need done below.

void FlashYellow()
{
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);   
  delay(100);               
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW);   
  delay(100);               
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);  
  delay(100);               
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW); 
  delay(100);             
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);
  delay(100);
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW); 
  delay(100);
  digitalWrite(ledPin0, HIGH);
  digitalWrite(ledPin2, HIGH);
  delay(100);             
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW);   
  delay(100);
}

void FlashWhite()
{
  digitalWrite(ledPin0, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);   
  delay(100);               
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW);   
  delay(100);               
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);  
  delay(100);               
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW); 
  delay(100);             
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);
  delay(100);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW); 
  delay(100);
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin3, HIGH);
  delay(100);             
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin3, LOW);   
  delay(100);
}

What I want to do is this:

2 on-off-on center off toggle switches(the toggle switched are just like you posted before) and 1 pushbutton.

This i got working good.
First Toggle Switch does this correctly:
flip Toggle Switch up turn all amber LEDs on. = buttonPin0
flip Toggle Switch down all white LEDs on. = buttonPin1

here's where I can't get it to working.
Second Toggle Switch Should do:
flip Toggle Switch up turn all amber LEDs to strobe on. = buttonPin2
flip Toggle Switch down turn all white LEDs to strobe on. =buttonPin3

if the second toggle switch are turned on (either up of down)

I want to be able to press the 1 pushbutton and switch between different strobing patterns for the correct color of LEDs selected by toggle switch = buttonPin4

If I flip the toggle switch up, it should start all the amber(yellow) LEDs strobing, and if i press the pushbutton( while the toggle switch is up) change between strobing patterns only for amber LEDs. (All White LEDs should be off)
If I flip the toggle switch down, it should start all the white LEDs strobing, and if i press the pushbutton( while the toggle switch is down) change between strobing patterns only for white LEDs. (All Amber(yellow) LEDs should be off)
Finally if the toggle switch is on the center position (off) I want NO LEDs to be lit.

The pushbutton for the strobe patterns should only work if the toggle switch is flipped up or down.

Thanks

Steve

is it working?? have you done my previous thread

Yes sorry it is working. I'm sorry I haven't replied. For some reason I wasn't getting notifications... Weird I know.

AMPS-N:

 int buttonState4 = digitalRead(buttonPin4);

{
    if (buttonState4 == HIGH)
    {
      if (oldState == LOW)
      {
        state++;
        if (state > 12) state = 0;
      }
    }
  }




This part of code has fault. You not set default state of oldstate i.e low or High.
What does it means???

oldstate is a global - it is initialised to zero.