Christmas Tree

Good evening,
First at all, sorry for my English.
I'm new in the Arduino's World and I'd want to create a Christmas Tree like that in the figure and I wrote the program, but I don't think it is good.
I'd want also put a botton before the circuit that every "touch" I'll put to the Button it will be change the function of the Christmas Tree.
So:

First Touch:
All the Leds Light On and a second later Light Off.

Second Touch:
The Leds Turn On one by one e Turn Off one by one.

Third Touch:
Some Leds Light On and after Light On the other Leds.
Some Leds Light Off and after Light Off the other Leds.

Fourth Touch:
The Leds Light On and Light Off sequentially.

I put the program I wrote and the image of a similar Christmas Tree in "Attachments".

Help me please to finish this project. I'd want to give as a present.

If someone speaks Italian it'd be fantastic!!!

Thanks so much!!!

albero-di-natale-16-led-500x500.jpg

Albero Di Natale.txt (8.78 KB)

Make life a bit cleaner by using more compact code:
Make functions AFTER the void loop() for the different things you want to do. Here is a function for turning all LEDs on and then another function for turning them all off after x time.

void setup() {
  // put your setup code here, to run once:

}

void loop() {

  //calls the function. Make a list of your custom functions in here.
  all_on_all_off(5);

}


//A Function to turn all on....delay (x) seconds and then turn all LEDs off
void all_on_all_off(int x) {

  for (byte i = 2; i < 13; i++) {

    digitalWrite(i, HIGH);

  }
  delay(x * 1000);

  for (byte i = 2; i < 13; i++) {

    digitalWrite(i, LOW);

  }

}

I was bored so I will give you a head start by removing all the delays in your code.

just redesign the loop code to read a button and advance rather than letting the state advance on its own (remove the timer in the loop also as it replacing large delays in your original code)

got bored naming things so im sure you can use edit-find word and replace with better names

// ALBERO DI NATALE
byte ledArray[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
byte leftArray[] = {12, 7, 5, 8, 3, 4};
byte rightArray[] = {11, 9, 2, 10, 6, 13};
byte oddArray[] = {2, 9, 11, 4, 7, 5, 12, 6, 8, 3, 10};

unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
unsigned long previousMillis4 = 0;
unsigned long previousMillis5 = 0;
unsigned long currentMillis;
byte state = 0;
unsigned long wait;
void setup() {
  Serial.begin(9600);
  for (byte x = 0; x < 12; x = x + 1) {
    //do this 12 times
    pinMode (ledArray[x], OUTPUT);
  }
}

void loop() {
  currentMillis = millis();

  if (currentMillis - previousMillis4 >= wait) {
    switch (state) {
      case 0:
      previousMillis5 = currentMillis;
        state = 1;
        break;
      case 1:
        pattern1();
        break;
      case 2:
        pattern2();
        break;
      case 3:
        pattern3();
        break;
      case 4:
        pattern4();
        break;
    }
  }
}


void pattern1() {
static byte ledOn;
 if (currentMillis - previousMillis5 >= 1000) {
   ledOn=1;
 }
 if (ledOn==0){
  for (byte x = 0; x < 12; x = x + 1) {
    digitalWrite  (ledArray[x], HIGH);
  }
 }else{
 for (byte x = 0; x < 12; x = x + 1) {
      digitalWrite  (ledArray[x], LOW);
    }
    previousMillis4 = currentMillis;
    wait = 1000;
    state = 2;
    ledOn=0;
  }
}

void pattern2() {
  static byte ledDir;
  static byte ledPosition;
  if (currentMillis - previousMillis1 >= 500) {
    if (ledDir == 0) {
      digitalWrite  (ledArray[ledPosition], HIGH);
      ledPosition++;//add to counter called ledPosition
    } else {
      digitalWrite  (ledArray[ledPosition], LOW);
      ledPosition--;
    }
    previousMillis1 = currentMillis;//take a new time stamp
  }
  if (ledPosition >= 12) {
    ledDir = 1;
  }
  if (ledPosition <= 0) {
    ledDir=0;
    ledPosition = 0;
    previousMillis4 = currentMillis;
    wait = 1500;
    state = 3;
  }
}

void pattern3()  {
  static byte cycle;

  if (currentMillis - previousMillis2 >= 1000) {
    cycle++;
    previousMillis2 = currentMillis;
  }
  switch (cycle) {
    case 1:
      for (byte x = 0; x < 6; x = x + 1) {
        digitalWrite  (leftArray[x], HIGH);
      }
      break;
    case 2:
      for (byte x = 0; x < 6; x = x + 1) {
        digitalWrite  (rightArray[x], HIGH);
      }
      break;
    case 3:
      break;
    case 4:
      for (byte x = 0; x < 6; x = x + 1) {
        digitalWrite  (leftArray[x], LOW);
      }
      break;
    case 5:
      for (byte x = 0; x < 6; x = x + 1) {
        digitalWrite  (rightArray[x], LOW);
      }
      previousMillis4 = currentMillis;
      wait = 1500;
      cycle = 0;
      state = 4;
      break;
  }
}

void pattern4()   {
  static byte ledthing;
  static byte even;
  static byte ledspot;
  byte oddArray[] = {2, 9, 11, 4, 7, 5, 12, 6, 8, 3, 10};
  if (currentMillis - previousMillis3 >= 500) {
    ledthing++;
    if (even == 1) {
    digitalWrite  (oddArray[ledspot], HIGH);
  } else {
    digitalWrite  (oddArray[ledspot], LOW);
  ledspot++;
  }
    
    previousMillis3 = currentMillis;
  }
  if (ledthing >= 24) {
    digitalWrite(13, LOW);
    ledthing = 0;
    ledspot = 0;
    previousMillis4 = currentMillis;
    wait = 1500;
    state = 0;
  } else {
    digitalWrite(13, HIGH);
  }
  even = ledthing % 2;
}