How to repeat piece od script

hello, I have a problem with repeating one or more pieces of script (LedShow) in loop.
Script is working with IR remote control and without errors but without repeating LedShow script.
And is it possible to make simple script?

IR_Control_led_3case.ino (7.12 KB)

I’m sorry but I can’t figure out what you wanted the sketch to do. It looks like you show a pattern of lights when a button press is received from the IR remote. When do you want the pattern to repeat?

If you want the pattern to repeat until a different pattern is chosen you would use the IR button press only to set which pattern is repeating. Then further on in loop() you would display the pattern. That way you don’t have to wait for a button press to play the pattern again:

#include <IRremote.h>

int Pattern = 0;  // show number
const int RECV_PIN = 4;
int num;
const int led0 = 13;
const int led1 = 12;
const int led2 = 11;
const int led3 = 10;
const int led4 = 9;
const int led5 = 8;
const int led6 = 7;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //for serial monitoring to work
  irrecv.enableIRIn(); // start the receiver

  pinMode(led0, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
}

void loop() {
  if (irrecv.decode(&results)) {
    unsigned long num = results.value;
    Serial.println(results.value, HEX); //serial monitoring
    irrecv.resume();

    // Act on the received key code
    switch (num) {
      case 0xFD02FD: // First LED show
        Pattern = 1;
        break;

      case 0xFD00FF:  // Second LED show
        Pattern = 2;
        break;

      case 0xFD42BD: // Third LED show
        Pattern = 3;
        break;
    }

  }

  // Show the currently selected pattern again
  switch (Pattern) {
    case 0:  // No pattern
      break;

    case 1: // First LED show=
      digitalWrite(led6, HIGH);
      delay(50);
      digitalWrite(led6, LOW);
      digitalWrite(led5, HIGH);
      delay(50);
      digitalWrite(led5, LOW);
      digitalWrite(led4, HIGH);
      delay(50);
      digitalWrite(led4, LOW);
      digitalWrite(led3, HIGH);
      delay(50);
      digitalWrite(led3, LOW);
      digitalWrite(led2, HIGH);
      delay(50);
      digitalWrite(led2, LOW);
      digitalWrite(led1, HIGH);
      delay(50);
      digitalWrite(led1, LOW);
      digitalWrite(led0, HIGH);
      delay(25);

      digitalWrite(led0, LOW);
      digitalWrite(led1, HIGH);
      delay(50);
      digitalWrite(led1, LOW);
      digitalWrite(led2, HIGH);
      delay(50);
      digitalWrite(led2, LOW);
      digitalWrite(led3, HIGH);
      delay(50);
      digitalWrite(led3, LOW);
      digitalWrite(led4, HIGH);
      delay(50);
      digitalWrite(led4, LOW);
      digitalWrite(led5, HIGH);
      delay(50);
      digitalWrite(led5, LOW);
      digitalWrite(led6, HIGH);
      delay(50);
      digitalWrite(led5, HIGH);
      delay(50);
      digitalWrite(led4, HIGH);
      delay(50);
      digitalWrite(led3, HIGH);
      delay(50);
      digitalWrite(led2, HIGH);
      delay(50);
      digitalWrite(led1, HIGH);
      delay(50);
      digitalWrite(led0, HIGH);
      delay(50);
      break;


    case 2:  // Second LED show
      digitalWrite(led0, LOW);
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led6, LOW);

      digitalWrite(led6, HIGH);
      delay(50);
      digitalWrite(led6, LOW);
      digitalWrite(led5, HIGH);
      delay(50);
      digitalWrite(led5, LOW);
      digitalWrite(led4, HIGH);
      delay(50);
      digitalWrite(led4, LOW);
      digitalWrite(led3, HIGH);
      delay(50);
      digitalWrite(led3, LOW);
      digitalWrite(led2, HIGH);
      delay(50);
      digitalWrite(led2, LOW);
      digitalWrite(led1, HIGH);
      delay(50);
      digitalWrite(led1, LOW);
      digitalWrite(led0, HIGH);
      delay(25);

      digitalWrite(led0, LOW);
      digitalWrite(led1, HIGH);
      delay(50);
      digitalWrite(led1, LOW);
      digitalWrite(led2, HIGH);
      delay(50);
      digitalWrite(led2, LOW);
      digitalWrite(led3, HIGH);
      delay(50);
      digitalWrite(led3, LOW);
      digitalWrite(led4, HIGH);
      delay(50);
      digitalWrite(led4, LOW);
      digitalWrite(led5, HIGH);
      delay(50);
      digitalWrite(led5, LOW);
      digitalWrite(led6, HIGH);
      delay(50);
      digitalWrite(led5, HIGH);
      delay(50);
      digitalWrite(led4, HIGH);
      delay(50);
      digitalWrite(led3, HIGH);
      delay(50);
      digitalWrite(led2, HIGH);
      delay(50);
      digitalWrite(led1, HIGH);
      delay(50);
      digitalWrite(led0, HIGH);
      delay(50);
      break;

    case 3:  // Third LED show
      digitalWrite(led3, HIGH);
      delay(50);

      digitalWrite(led3, LOW);
      digitalWrite(led2, HIGH);
      digitalWrite(led4, HIGH);
      delay(100);

      digitalWrite(led2, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led1, HIGH);
      digitalWrite(led5, HIGH);
      delay(100);

      digitalWrite(led1, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led0, HIGH);
      digitalWrite(led6, HIGH);
      delay(100);

      digitalWrite(led0, LOW);
      digitalWrite(led6, LOW);
      digitalWrite(led5, HIGH);
      digitalWrite(led1, HIGH);
      delay(100);

      digitalWrite(led5, LOW);
      digitalWrite(led1, LOW);
      digitalWrite(led4, HIGH);
      digitalWrite(led2, HIGH);
      delay(100);

      digitalWrite(led4, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, HIGH);
      delay(50);
      break;


    case 4:
      digitalWrite(led0, LOW);
      digitalWrite(led1, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led6, LOW);

      digitalWrite(led3, HIGH);
      delay(50);

      digitalWrite(led3, LOW);
      digitalWrite(led2, HIGH);
      digitalWrite(led4, HIGH);
      delay(100);

      digitalWrite(led2, LOW);
      digitalWrite(led4, LOW);
      digitalWrite(led1, HIGH);
      digitalWrite(led5, HIGH);
      delay(100);

      digitalWrite(led1, LOW);
      digitalWrite(led5, LOW);
      digitalWrite(led0, HIGH);
      digitalWrite(led6, HIGH);
      delay(100);

      digitalWrite(led0, LOW);
      digitalWrite(led6, LOW);
      digitalWrite(led5, HIGH);
      digitalWrite(led1, HIGH);
      delay(100);

      digitalWrite(led5, LOW);
      digitalWrite(led1, LOW);
      digitalWrite(led4, HIGH);
      digitalWrite(led2, HIGH);
      delay(100);

      digitalWrite(led4, LOW);
      digitalWrite(led2, LOW);
      digitalWrite(led3, HIGH);
      delay(50);
      break;

    case 5:
      digitalWrite(led0, LOW);
      delay(50);
      digitalWrite(led1, LOW);
      delay(50);
      digitalWrite(led2, LOW);
      delay(50);
      digitalWrite(led3, LOW);
      delay(50);
      digitalWrite(led4, LOW);
      delay(50);
      digitalWrite(led5, LOW);
      delay(50);
      digitalWrite(led6, LOW);
      delay(50);
      break;

    case 6:
      digitalWrite(led0, LOW);
      delay(50);
      digitalWrite(led1, LOW);
      delay(50);
      digitalWrite(led2, LOW);
      delay(50);
      digitalWrite(led3, LOW);
      delay(50);
      digitalWrite(led4, LOW);
      delay(50);
      digitalWrite(led5, LOW);
      delay(50);
      digitalWrite(led6, LOW);
      delay(50);

  }
}  // end of loop()

Thank you, You help me so much, now I understand how to repeat pattern until button is press again :slight_smile: