Double Blink and delay for 1000 MS without delay()

why I wanted to know BlinkwithoutDelay is for my below mentioned project. The delay() is halting the system and didnot allow the button to respond.. But still I canot figured out how to solve it... Very disappointing.. Here is the code:

const int rightLed=12;
const int leftLed=11;
const int leftButton=8;
const int rightButton=9;
const int blinkerButton=10;
uint8_t brightness = 0;    // how bright the LED is
uint8_t fadeAmount = 5;
byte counter = 0;
byte OldCounter = 0;


bool leftButtonState = 1;
bool rightButtonState = 1;
bool blinkerButtonState = 1;


void setup()
{
  pinMode(leftLed,OUTPUT);
  pinMode(rightLed,OUTPUT);
  pinMode(leftButton,INPUT_PULLUP);
  pinMode(rightButton,INPUT_PULLUP);
  pinMode(blinkerButton,INPUT_PULLUP);
}




void loop()
{
  OldCounter = counter;
  switch (OldCounter)
  {
    case 1: Flasher1(); break;
    case 2: Flasher2(); break;
    case 3: Flasher3(); break;
    case 4: Flasher4(); break;
    case 5: Flasher5(); break;
    case 6: Flasher6(); break;
    case 7: Flasher7(); break;
    case 8: Flasher8(); break;
    case 9: Flasher9(); break;
    case 10: Flasher10(); break;
    case 11: Flasher11(); break;
    case 12: LeftIndicator(); break;
    case 13: RightIndicator(); break;
    default: Flasher2();
  }
  //for leftbutton
  leftButtonState=digitalRead(leftButton);
  if (leftButtonState == 0)
  {
   
    counter = 12;
  }


  //for right button
  rightButtonState=digitalRead(rightButton);
  if (rightButtonState== 0)
  {
  
    counter = 13;
  }

  //for blinker button
  blinkerButtonState=digitalRead(blinkerButton);
  if (blinkerButtonState == 0) {
    {
      counter++;
      if (counter > 11)counter = 1;
    }
  }
}


void Flasher1() {
  analogWrite(PB0, brightness);
  analogWrite(PB1, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {

    fadeAmount = -fadeAmount;
    if (brightness == 0)   delay(2000) ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(50) ;
}
void Flasher2()
{
  digitalWrite(leftLed, HIGH);  digitalWrite(rightLed, HIGH);     delay(500) ;
  digitalWrite(leftLed, LOW); digitalWrite(rightLed, LOW);    delay(500) ;
}
void Flasher3()
{
  LeftLedFlash();   LeftLedFlash();   LeftLedFlash();      LeftLedFlash();    delay(200) ;
  RightLedFlash();  RightLedFlash();  RightLedFlash();     RightLedFlash();   delay(200) ;
}

void Flasher4()
{
  LeftLedFlash();  LeftLedFlash();    delay(1000) ;
  RightLedFlash(); RightLedFlash();   delay(1000) ;
}
void Flasher5()
{
  LeftLedFlash();     delay(80);
  LeftLedFlash();     delay(1000) ;
  RightLedFlash();  delay(80) ;
  RightLedFlash();  delay(1000) ;
}

void Flasher6()
{
  LeftLedFlash();      RightLedFlash();      delay(60) ;
  LeftLedFlash();      RightLedFlash();     delay(500) ;
}
void Flasher7()
{
  digitalWrite(rightLed, HIGH);  digitalWrite(leftLed, HIGH);  delay(50) ;
  digitalWrite(rightLed, LOW); digitalWrite(leftLed, LOW); delay(50) ;
  digitalWrite(rightLed, HIGH);  digitalWrite(leftLed, HIGH);  delay(50) ;
  digitalWrite(rightLed, LOW); digitalWrite(leftLed, LOW); delay(500) ;
}
void Flasher8()
{
  digitalWrite(rightLed, HIGH);      delay(50) ;
  digitalWrite(rightLed, LOW);     digitalWrite(leftLed, HIGH);      delay(100) ;
  digitalWrite(leftLed, LOW);      digitalWrite(rightLed, HIGH);     delay(50) ;
  digitalWrite(rightLed, LOW);     digitalWrite(leftLed, HIGH);      delay(100) ;
  digitalWrite(leftLed, LOW);      digitalWrite(rightLed, HIGH);     delay(50) ;
  digitalWrite(rightLed, LOW);     delay(1500) ;
}
void Flasher9()
{
  for ( uint8_t i = 0; i < 3; i++)
  {
    digitalWrite(leftLed, HIGH);    delay(50) ;   digitalWrite(leftLed, LOW);    delay(50) ;
  }
  for (uint8_t i = 0; i < 3; i++)
  {
    digitalWrite(rightLed, HIGH);   delay(50) ;   digitalWrite(rightLed, LOW);    delay(50) ;
  }
}
void Flasher10()
{
  digitalWrite(leftLed, HIGH);    delay(50) ;    digitalWrite(leftLed, LOW);
  digitalWrite(rightLed, HIGH);   delay(50) ;    digitalWrite(rightLed, LOW);
  delay(2000) ;
}

void Flasher11()
{
  digitalWrite(leftLed, HIGH); digitalWrite(rightLed, HIGH);   delay(50) ;  digitalWrite(leftLed, LOW);  digitalWrite(rightLed, LOW);
  delay(3000) ;
}
void LeftLedFlash()
{
  digitalWrite(leftLed, HIGH);  delay(30) ;  digitalWrite(leftLed, LOW);  delay(30) ;
}
void RightLedFlash()
{
  digitalWrite(rightLed, HIGH);  delay(30) ;
  digitalWrite(rightLed, LOW); delay(30) ;
}
void LeftIndicator()
{
  digitalWrite(rightLed, LOW);
  digitalWrite(leftLed, HIGH);  delay(500) ;
  digitalWrite(leftLed, LOW); delay(500) ;
}
void RightIndicator()
{
  digitalWrite(leftLed, LOW);
  digitalWrite(rightLed, HIGH);  delay(500) ;
  digitalWrite(rightLed, LOW); delay(500) ;
}

Ok, this is suddenly much more complicated. But it is not impossible.

Question: if we help you get this working, what next? More LEDs, more patterns, or is this everything?

I am thinking of a "player piano" approach to solve this, with a section of the "roll" for each pattern, and that section gets repeated until the "track" or "mode" changes.

... and changes the underlying nature of the project. It might deserve to be spun off into a new thread.

Yes this much of my project. I need it.
Cant understand your example of Player Pinno.
can u pls make a short programe for it..
pls

I have converted Flasher2() to Flasher5() using my "player piano" idea. It compiles but I have not tested it, so if there are any problems, please be sure to explain them fully.

const int rightLed=12;
const int leftLed=11;
const int leftButton=8;
const int rightButton=9;
const int blinkerButton=10;
uint8_t brightness = 0;    // how bright the LED is
uint8_t fadeAmount = 5;
byte counter = 0;
byte OldCounter = 0;

struct {
  byte leftLed;
  byte rightLed;
  int period;
} sequence[] = {
  /* Flasher 2 */
  {HIGH, HIGH, 500},
  {LOW,  LOW,  500},
  /* Flasher 3 */
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30+200},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30+200},
  /* Flasher 4 */
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30+1000},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30+1000},
  /* Flasher 5 */
  {HIGH, LOW,   30},
  {LOW,  LOW,   30+80},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30+1000},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30+80},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30+1000}
};

int step;
unsigned long lastChange;

void Flasher(int first, int last) {
sequence[step].period) { */
  if (step < first || step > last || millis() - lastChange >= sequence[step].period) {  /* <-- correction made later */
    /* move to next step */
    step++;
    if (step < first || step > last) step = first;
    /* Update Leds */
    digitalWrite(leftLed, sequence[step].leftLed);
    digitalWrite(rightLed, sequence[step].rightLed);
    lastChange = millis();
  }
}


bool leftButtonState = 1;
bool rightButtonState = 1;
bool blinkerButtonState = 1;


void setup()
{
  pinMode(leftLed,OUTPUT);
  pinMode(rightLed,OUTPUT);
  pinMode(leftButton,INPUT_PULLUP);
  pinMode(rightButton,INPUT_PULLUP);
  pinMode(blinkerButton,INPUT_PULLUP);
}




void loop()
{
  OldCounter = counter;
  switch (OldCounter)
  {
    case 1: Flasher1(); break;
    case 2: Flasher(0, 1); break;
    case 3: Flasher(2, 17); break; /* <-- correction made later */
    case 4: Flasher(18, 25); break; /* <-- correction made later */
    case 5: Flasher(26, 33); break; /* <-- correction made later */
    case 6: Flasher6(); break;
    case 7: Flasher7(); break;
    case 8: Flasher8(); break;
    case 9: Flasher9(); break;
    case 10: Flasher10(); break;
    case 11: Flasher11(); break;
    case 12: LeftIndicator(); break;
    case 13: RightIndicator(); break;
    default: Flasher(0, 1);
  }
  //for leftbutton
  leftButtonState=digitalRead(leftButton);
  if (leftButtonState == 0)
  {
   
    counter = 12;
  }


  //for right button
  rightButtonState=digitalRead(rightButton);
  if (rightButtonState== 0)
  {
  
    counter = 13;
  }

  //for blinker button
  blinkerButtonState=digitalRead(blinkerButton);
  if (blinkerButtonState == 0) {
    {
      counter++;
      if (counter > 11)counter = 1;
    }
  }
}


void Flasher1() {
  analogWrite(PB0, brightness);
  analogWrite(PB1, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {

    fadeAmount = -fadeAmount;
    if (brightness == 0)   delay(2000) ;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(50) ;
}

void Flasher6()
{
  LeftLedFlash();      RightLedFlash();      delay(60) ;
  LeftLedFlash();      RightLedFlash();     delay(500) ;
}
void Flasher7()
{
  digitalWrite(rightLed, HIGH);  digitalWrite(leftLed, HIGH);  delay(50) ;
  digitalWrite(rightLed, LOW); digitalWrite(leftLed, LOW); delay(50) ;
  digitalWrite(rightLed, HIGH);  digitalWrite(leftLed, HIGH);  delay(50) ;
  digitalWrite(rightLed, LOW); digitalWrite(leftLed, LOW); delay(500) ;
}
void Flasher8()
{
  digitalWrite(rightLed, HIGH);      delay(50) ;
  digitalWrite(rightLed, LOW);     digitalWrite(leftLed, HIGH);      delay(100) ;
  digitalWrite(leftLed, LOW);      digitalWrite(rightLed, HIGH);     delay(50) ;
  digitalWrite(rightLed, LOW);     digitalWrite(leftLed, HIGH);      delay(100) ;
  digitalWrite(leftLed, LOW);      digitalWrite(rightLed, HIGH);     delay(50) ;
  digitalWrite(rightLed, LOW);     delay(1500) ;
}
void Flasher9()
{
  for ( uint8_t i = 0; i < 3; i++)
  {
    digitalWrite(leftLed, HIGH);    delay(50) ;   digitalWrite(leftLed, LOW);    delay(50) ;
  }
  for (uint8_t i = 0; i < 3; i++)
  {
    digitalWrite(rightLed, HIGH);   delay(50) ;   digitalWrite(rightLed, LOW);    delay(50) ;
  }
}
void Flasher10()
{
  digitalWrite(leftLed, HIGH);    delay(50) ;    digitalWrite(leftLed, LOW);
  digitalWrite(rightLed, HIGH);   delay(50) ;    digitalWrite(rightLed, LOW);
  delay(2000) ;
}

void Flasher11()
{
  digitalWrite(leftLed, HIGH); digitalWrite(rightLed, HIGH);   delay(50) ;  digitalWrite(leftLed, LOW);  digitalWrite(rightLed, LOW);
  delay(3000) ;
}
void LeftLedFlash()
{
  digitalWrite(leftLed, HIGH);  delay(30) ;  digitalWrite(leftLed, LOW);  delay(30) ;
}
void RightLedFlash()
{
  digitalWrite(rightLed, HIGH);  delay(30) ;
  digitalWrite(rightLed, LOW); delay(30) ;
}
void LeftIndicator()
{
  digitalWrite(rightLed, LOW);
  digitalWrite(leftLed, HIGH);  delay(500) ;
  digitalWrite(leftLed, LOW); delay(500) ;
}
void RightIndicator()
{
  digitalWrite(leftLed, LOW);
  digitalWrite(rightLed, HIGH);  delay(500) ;
  digitalWrite(rightLed, LOW); delay(500) ;
}

You should be able to convert the other functions in the same way. However, Flasher1() is different to the others and does not fit with my "player piano" idea, so that must be converted using the typical "blink without delay" technique.

Sure Sir, I will check today evening and tell u the outcome..
Thanks for the effort you made

Hi @PaulRB I have tried your code. the arduino run it. but it doesnot blink the default flasher squence in 'Flasher(0,1);break' . Then I have just tried part of your code for my self learning. But the error same. Both the LEDs are not blinking, only continously glowing. Here is the Code:

const int RightLed = 12;
const int LeftLed = 11;
struct {
  byte leftLed;
  byte rightLed;
  int period;
} sequence[] = {

  {HIGH, HIGH, 500},
  {LOW,  LOW,  500}
   };

int step;
unsigned long lastChange;

void Flasher(int first, int last) {
  if (step < first || step > last || lastChange - millis() >= sequence[step].period) {
    /* move to next step */
    step++;
    if (step < first || step > last) step = first;
    /* Update Leds */
    digitalWrite(LeftLed, sequence[step].leftLed);
    digitalWrite(RightLed, sequence[step].rightLed);
    lastChange = millis();
  }
}
void setup()
{
  pinMode(LeftLed, OUTPUT);
  pinMode(RightLed, OUTPUT);
 //Serial.begin(9600);
}

void loop()
{
 Flasher(0,1);
}

Thank you.

I made a dumb error!

  if (step < first || step > last || millis() - lastChange >= sequence[step].period) {

solution pls

The correction is in post #49 !

thanks

I found more errors. It seems I cannot count. See if you can find them also.

pls pls.. I need it to run.. I am just beginner. pls let me know where is error

Even a beginner can find these errors easily. If you can count, you will find them!

yes i GOt. the arrey sequency in blink3 it may be 2 to 18. RIght?

2 to 17.

The other errors are similar. I corrected the code in post #46, indicating where the changes were made.

Thanks @PaulRB, @GolamMostafa and all others for making my project clean and beautiful.. Learned a lot especially from @PaulRB. Here is the complete project... I will add some other features in this. But This sketch is somehow complete in some extent.

const int rightLed = 12;
const int leftLed = 11;
const int leftButton = 8;
const int rightButton = 9;
const int blinkerButton = 10;
uint8_t brightness = 0;    // how bright the LED is
uint8_t fadeAmount = 5;
byte counter;
byte OldCounter = 0;
unsigned long previousMillis = 0;
unsigned long interval = 30;

long leftButtonTime = 0;
long rightButtonTime = 0;
long blinkerButtonTime = 0; // the last time the output pin was toggled
long debounceDelay = 80;

//Button Press State
bool leftButtonState = 1;
bool rightButtonState = 1;
bool blinkerButtonState = 1;

//Indicator Status
bool leftIndicatorState = 0;
bool rightIndicatorState = 0;

struct {
  byte leftLed;
  byte rightLed;
  int period;
} sequence[] = {
  /* Flasher 2 */
  {HIGH, HIGH, 500},
  {LOW,  LOW,  500},
  /* Flasher 3 */
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30 + 200},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30 + 200},

  // Flasher 4  //array 18 to 25
  {HIGH, LOW,   30},
  {LOW,  LOW,   30},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30 + 1000},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30 + 1000},
  // Flasher 5 //array 26 to 33
  {HIGH, LOW,   30},
  {LOW,  LOW,   30 + 80},
  {HIGH, LOW,   30},
  {LOW,  LOW,   30 + 1000},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30 + 80},
  {LOW, HIGH,   30},
  {LOW,  LOW,   30 + 1000},
  // Flasher 6 //array 34 to 39
  {HIGH, LOW,   80},
  {LOW,  HIGH,   80},
  {LOW, LOW,   1000},
  {LOW,  HIGH,  80},
  {HIGH, LOW,   80},
  {LOW,  LOW,  1000},



  // Flasher 7  //array 42 to 45
  {HIGH, HIGH,  50},
  {LOW,  LOW,   50},
  {HIGH, HIGH,  50},
  {LOW,  LOW,   500},

  // Flasher 8  //array 46 to 55
  {HIGH, LOW,  50},
  {LOW,  LOW,   0},
  {LOW, HIGH,  100},
  {LOW,  LOW,   0},
  {HIGH, LOW,  50},
  {LOW,  LOW,   0},
  {LOW, HIGH,  100},
  {LOW,  LOW,   0},
  {HIGH, LOW,  50},
  {LOW,  LOW,   1500},

  //Flasher 9 //array 56 to 67
  {HIGH, LOW,  50},
  {LOW,  LOW,   0},
  {HIGH, LOW,  50},
  {LOW,  LOW,   0},
  {HIGH, LOW,  50},
  {LOW,  LOW,   0 + 300},
  {LOW, HIGH,  50},
  {LOW, LOW,   0},
  {LOW, HIGH,  50},
  {LOW, LOW,   0},
  {LOW, HIGH,  50},
  {LOW, LOW,   0 + 300},

  //Flasher 10//array 68 to 71
  {HIGH, LOW,  50},
  {LOW,  LOW,   0},
  {HIGH, LOW,  50},
  {LOW,  LOW,   2000},

  //Flasher 11 //array 72 to 73
  {HIGH, HIGH,  50},
  {LOW,  LOW,   0 + 3000},

  // Flasher 12 Left Indicator//array 74 to 75
  {HIGH, LOW,   500},
  {LOW,  LOW,   500},
  // Flasher 13 Right Indicator //array 76 to 77
  {LOW, HIGH,   500},
  {LOW,  LOW,   500},
  // Flasher 14 NoFlash //array 78 to 78
  {LOW,  LOW,   500}

}; // END STRUCTURE

int step;
unsigned long lastChange;

void Flasher(int first, int last) {
  if (step < first || step > last || millis() - lastChange >= sequence[step].period) {
    /* move to next step */
    step++;
    if (step < first || step > last) step = first;
    /* Update Leds */
    digitalWrite(leftLed, sequence[step].leftLed);
    digitalWrite(rightLed, sequence[step].rightLed);
    lastChange = millis();
  }
}

void setup()
{
  pinMode(leftLed, OUTPUT);
  pinMode(rightLed, OUTPUT);
  pinMode(leftButton, INPUT_PULLUP);
  pinMode(rightButton, INPUT_PULLUP);
  pinMode(blinkerButton, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop()
{
  OldCounter = counter;
  switch (OldCounter)
  {
    case 1: Flasher1(); Serial.println("1"); break;
    case 2: Flasher(0, 1); Serial.println("2"); break;
    case 3: Flasher(2, 17); Serial.println("3"); break;
    case 4: Flasher(18, 25); Serial.println("4"); break;
    case 5: Flasher(26, 33); Serial.println("5"); break;
    case 6: Flasher(34, 41); Serial.println("6"); break;
    case 7: Flasher(42, 45); Serial.println("7"); break;
    case 8: Flasher(46, 55); Serial.println("8"); break;
    case 9: Flasher(56, 67); Serial.println("9"); break;
    case 10: Flasher(68, 71); Serial.println("10"); break;
    case 11: Flasher(72, 73); Serial.println("11"); break;
    case 12: Flasher(74, 75); Serial.println("12"); break;
    case 13: Flasher(76, 77); Serial.println("13"); break;
    case 14: Flasher(78, 78); Serial.println("14"); break;
    default: Flasher(34, 39); Serial.println("Default"); break;
  }
  //for leftbutton
  leftButtonState = digitalRead(leftButton);
  if ((millis() - leftButtonTime) > debounceDelay) {
    if (leftButtonState == 0 && leftIndicatorState == 0)
    {
      leftIndicatorState = 1;
      counter = 12;
    }
    else if (leftButtonState == 0 && leftIndicatorState == 1)
    {
      leftIndicatorState = 0;
      counter = 14;
    } leftButtonTime = millis();
  }

  //for right button
  rightButtonState = digitalRead(rightButton);
  if ((millis() - rightButtonTime) > debounceDelay) {
    if (rightButtonState == 0 && rightIndicatorState == 0 && (millis() - 100))
    {
      rightIndicatorState = 1;
      counter = 13;
    }

    else if (rightButtonState == 0 && rightIndicatorState == 1 && millis() - 100)
    {
      rightIndicatorState = 0;
      counter = 14;
    } rightButtonTime = millis();
  }

  //for blinker button
  blinkerButtonState = digitalRead(blinkerButton);
  if ((millis() - blinkerButtonTime) > debounceDelay) {
    if (blinkerButtonState == 0 && ( millis() - 100))
    {
      counter++;
      if (counter > 11)counter = 1;
    }
    blinkerButtonTime = millis();
  }
}

void noflash() {
  digitalWrite(rightLed, LOW);
  digitalWrite(leftLed, LOW);
}

void Flasher1() {
  unsigned long currentMillis = millis(); // grab current time
  analogWrite(leftLed, brightness);
  analogWrite(rightLed, brightness);

  if (currentMillis - previousMillis >= interval) {
    brightness = brightness + fadeAmount; // change the brightness for next time through the loop:
    previousMillis = millis();
  }

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 )
  { // reverse the direction of the fading at the ends of the fade:
    brightness = 0;
    fadeAmount = -fadeAmount;
  }
  if (brightness >= 255 )
  { // reverse the direction of the fading at the ends of the fade:
    brightness = 255;
    fadeAmount = -fadeAmount;
  }

}

Good work @t_tuku you have learned very quickly :grinning:

If you have any questions about how any parts of the code work, please ask. It is important to me that you understand it fully. The techniques might be useful to you again in future.

I noticed that you also converted Flasher1(). How is that working? Not well, I think. One of the led pins you are using is not pwm-capable, I think, so analogWrite() cannot dim that led. It will be on for PWM>=128 and off for PWM<128.

I also noticed lines like this in the patterns:

  {LOW,  LOW,   0},

These can be removed, they do nothing. Do not forget to adjust the first/last step numbers for that pattern and those following it.

  1. Sure Sir, I wll definitely request help from this forum for my any projects. And for you all I got some knowledge about C++ programming in Arduino.

2.Yes the Flasher1() run for only one pin. The other pin run only as per ur statement PWM>=128. Actually I want to set these code for my ATTINY13 and the PB0 and PB1 is same in both uc. Hence I didnot change the PIN number in ATMEGA328p.

  1. I need to completely off both the LEDs in the Switch case statement. So I created {LOW, LOW, 0},.
    Is there any option for this?

Thank you.

If both LEDs are off for less than 1 millisecond, that will not be visible, so you can remove it.

As an example:

  {HIGH, LOW,  50},
  {LOW,  LOW,   0},
  {HIGH, LOW,  50},

The effect of the {LOW, LOW, 0} step will be invisible, so you can simplify to a single step:

  {HIGH, LOW,  50+50},

And here:

  {LOW, HIGH,  100},
  {LOW,  LOW,   0},
  {HIGH, LOW,  50},

Can be simplified to:

  {LOW, HIGH,  100},
  {HIGH, LOW,  50},

With no visible difference.