Run each set of Codes at a Specified Time

Hello Everyone,

I am building a Volume Unit (VU) Meter out of Arduino Uno. I need to run the codes under the following conditions:

Given Codes:

  • VU Meter code
  • Effects 1 code
  • Effects 2 code
  • Effects 3 code
  • Effects 4 code

Problem:

  • I need the VU Meter to run for two (2) minutes, before proceeding to Effects 1.
  • Effects 1 needs to run for 30 seconds, before proceeding to Effects 2.
  • Effects 2 needs to run for 15 seconds, before proceeding to Effects 3.
  • Effects 3 needs to run for 15 seconds, before proceeding to Effects 4.
  • Effects 4 needs to run for 20 seconds, before looping back to the VU Meter which again will run for two (2) minutes, and do the same cycle again.

Kindly see my attachment for the raw codes.

Thank you very much.

-Kairus

vu_met with 4fx.txt (3.66 KB)

int music = A0;
int output,a;
int potval=A1;
int number_of_led[12] = { 2,3,4,5,6,7,8,9,10,11,12,13}; // Assign the pins for the leds
void setup()
{
for (a = 0; a < 12; a++)  
  pinMode(number_of_led[a], OUTPUT);
}

void loop()
{
potval=analogRead(A1);
output = analogRead(music);
potval=map (potval,0,1024,5,40);
output = output/potval;   

  if (output == 0) 
   {
   for(a = 0; a < 12; a++)
     {
     digitalWrite(number_of_led[a], LOW);
     }
  }
  
  else
  {
   for (a = 0; a < output; a++)
    {
     digitalWrite(number_of_led[a], HIGH);
    }
    
    for(a = a; a < 12; a++) 
     {
      digitalWrite(number_of_led[a], LOW);
    
     }
  }
}





//initializing a variable for digital pin 0 to 13

int led1 = 0;
int led2 = 1;
int led3 = 2;
int led4 = 3;
int led5 = 4;
int led6 = 5;
int led7 = 6;
int led8 = 7;
int led9 = 8;
int led10 = 9;
int led11 = 10;
int led12 = 11;
int led13 = 12;
int led14 = 13;



//Arduino 4 Effect code:-

#define t   30
#define t1  20
#define t2  100
#define t3  50

void setup() {
  // set up pins 0 to 13 as outputs
  for (int i = 0; i <= 13; i++) {
    pinMode(i, OUTPUT);
  }
  for(int i=0;i<=13;i++){
  digitalWrite(i, LOW);}
}
/////////////////////////////////////////////////////////////////////////////////Effect 1
void loop(){

 effect_1();
 effect_1();

 effect_2();
 effect_2();

 effect_3();
 effect_3();

 effect_4();
 effect_4();


  }
//left to right and right to left
void effect_1()
{
for(int i=0; i<=13; i++){
digitalWrite(i, HIGH);
delay(t1);
digitalWrite(i+1, HIGH);
delay(t1);
digitalWrite(i+2, HIGH);
delay(t1);
digitalWrite(i, LOW);
delay(t1);
digitalWrite(i+1, LOW);
delay(t1);
}
for(int i=13; i>=0; i--){
digitalWrite(i, HIGH);
delay(t1);
digitalWrite(i-1, HIGH);
delay(t1);
digitalWrite(i-2, HIGH);
delay(t1);
digitalWrite(i, LOW);
delay(t1);
digitalWrite(i-1, LOW);
delay(t1);
}
}
/////////////////////////////////////////////////////////////////////////////////Effect 2
void effect_2()
{
int count = 13; // keeps track of second LED movement

  // move first LED from left to right and second from right to left
  for (int i = 0; i <=13; i++) {
    clear();
    digitalWrite(i, HIGH);      // chaser 1
    digitalWrite(count, HIGH); // chaser 2
    count--;
    // stop LEDs from appearing to stand still in the middle
    if (count != 8) {
      delay(t2);
    }
  }

  // move first LED from right to left and second LED from left to right
  for (int i = 13; i >=0; i--) {
    clear();
    digitalWrite(i, HIGH);      // chaser 1
    digitalWrite(count, HIGH); // chaser 2
    count++;
    // stop LEDs from appearing to stand still in the middle
    if (count != 8) {
      delay(t2);
    }
  }
}

////////////////////////////////////////////////////////////////////////////////Effect 3

void effect_3()
{
for(int i=0; i<14; i++){
  digitalWrite(i, HIGH);
  delay(t3);
}
for(int i=0; i<14; i++){
  digitalWrite(i, LOW);
  delay(t3);
}


for(int i = 14; i>=0; i--){
  digitalWrite(i, HIGH);
  delay(t3);
}
for(int i = 14; i>=0; i--){
  digitalWrite(i, LOW);
  delay(t3);
}
}
  ///////////////////////////////////////////////////////////////////////////Effect 4
void effect_4()
{
for(int j = 0; j <= 13; j++){
  digitalWrite(j, HIGH);
  delay(t2);
  j=j+1;
  }
for(int j = 0; j <= 13; j++){
  digitalWrite(j, LOW);
  delay(t2);
  }

  for(int k = 13; k > 0; k--){
  digitalWrite(k, HIGH);
  delay(t2);
  k=k-1;
  }
for(int k = 13; k > 0; k--){
  digitalWrite(k, LOW);
  delay(t2);
  }
}

void clear(void)
{
  for (int i = 0; i <= 13; i++) {
    digitalWrite(i, LOW);
  }
}

You appear to have multiple setup functions.

Hi Kairus,

from the code you have posted I can conclude that your knowledge-level about programming needs some improvements

Of course you can ask here in the forum. But then you have to wait for the answers. If you start to learn how coding works you become more and more independent of waiting for answers.

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going.

best regards Stefan