At a loss for something simple

I have been searching and reading here and all over and can't find anything that helps that fits my situation.

What I have is, 8 sketches of LED patterns I want to combine into one sketch as different sequences, then use a single push button to advance to the next sequence, 1 through 8 and back to start. I don't think millis would br a good option as I have varying delays in the sequences to make them run accurately. I'm running 15 yellow LEDs on pins in to 11. 4 pairs are run in series.

I'm hoping I cam get direction as to where I may havea better shot at obtaining my final results.

Welcome to the forum

If you don't want to hold the button down until the end of the current pattern then millis() is the best way to do the timing

How is the data for the patterns held ?

Please post a couple of your sketches as examples, using code tags when you do

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

Which Arduino board are you using ?

I'm using an UNO R3 and have a couple Nano's on the way I want to use for the final project. I'm new to Arduino, though I have programmed way back in the day, so I have a basic understanding of how code works.

I started piecing together my sketches, starting with 2 patterns. I figure if I cam get 2 to work, implementing the other 6 won't be difficult. If you know what a flashing arrow board is on a construction site, I'm trying to replicate that. My individual sketches work as I want them to. It's the next step I can't seem to find be it because it's not what I need or I have no clue of what's going on.

I'll post my latest sketch with the 2 patterns. In each sketch, the setup and settings are the same. I'm also working from Android, I don't have a PC nor access to one.


int led1 = 1; //define pins 
int led2 = 2;
int led3 = 3;
int led4 = 4;
int led5 = 5;
int led6 = 6;
int led7 = 7;
int led8 = 8;
int led9 = 9;
int led10 = 10;
int led11 = 11;
int inPin = 12;

void  setup() {

// pin setup
    
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(3,OUTPUT);
pinMode(2,OUTPUT);
pinMode(1,OUTPUT);
pinMode(12,INPUT);
}



//sequence 1, left arrow, chase and flash

void  loop() {

digitalWrite(led11,HIGH);
digitalWrite(led9,HIGH);
delay(300);
digitalWrite(led11,LOW);
digitalWrite(led7,HIGH);
delay(300);
digitalWrite(led9,LOW);
digitalWrite(led6,HIGH);
delay(300);
digitalWrite(led5,HIGH);
digitalWrite(led7,LOW);
delay(300);
digitalWrite(led3,HIGH);
digitalWrite(led6,LOW);
delay(300);
digitalWrite(led3,LOW);
digitalWrite(led5,LOW);
digitalWrite(led1,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led7,LOW);
delay(300);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
digitalWrite(led4,LOW);
delay(300);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led7,HIGH);
digitalWrite(led9,HIGH);
digitalWrite(led11,HIGH);
delay(250);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
digitalWrite(led7,LOW);
digitalWrite(led9,LOW);
digitalWrite(led11,LOW);
delay(250);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led7,HIGH);
digitalWrite(led9,HIGH);
digitalWrite(led11,HIGH);
delay(250);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
digitalWrite(led7,LOW);
digitalWrite(led9,LOW);
digitalWrite(led11,LOW);
delay(250);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led7,HIGH);
digitalWrite(led9,HIGH);
digitalWrite(led11,HIGH);
delay(250);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
digitalWrite(led7,LOW);
digitalWrite(led9,LOW);
digitalWrite(led11,LOW);
delay(250);
digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led7,HIGH);
digitalWrite(led9,HIGH);
digitalWrite(led11,HIGH);
delay(250);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
digitalWrite(led7,LOW);
digitalWrite(led9,LOW);
digitalWrite(led11,LOW);
delay(250);
}

//sequence 2, left arrow all

void loop() {

digitalWrite(led1,HIGH);
digitalWrite(led2,HIGH);
digitalWrite(led4,HIGH);
digitalWrite(led5,HIGH);
digitalWrite(led6,HIGH);
digitalWrite(led7,HIGH);
digitalWrite(led9,HIGH);
digitalWrite(led11,HIGH);
delay(500);
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led4,LOW);
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
digitalWrite(led7,LOW);
digitalWrite(led9,LOW);
digitalWrite(led11,LOW);
delay(500);

}

Change the first loop to loop1, and the second to loop2. Now create a new loop and inside it place the following two statements
loop1();
loop2();
Now add more like that.

Read about capturing a button press: https://docs.arduino.cc/built-in-examples/digital/Debounce/

Use that information about button presses to make a counter. As the counter increases, use a "switch/case" to move to the next function.

This shows an example of calling functions from loop()

int counter;

void setup() {
  Serial.begin(115200);
}

void loop() {
  if (counter > 4) // limited to number of functions made
    counter = 0;
  switch (counter) { // use counter to select the function
    case (0): { // if counter is 0
        function_0(); // call this function
        break; // exit this case
      }
    case (1): {
        function_1();
        break;
      }
    case (2): {
        function_2();
        break;
      }
    case (3): {
        function_3();
        break;
      }
  }
  counter++; // increment function counter
  delay(1000);
}

void function_0() {
  Serial.print("f0 ");
}
void function_1() {
  Serial.print("f1 ");
}
void function_2() {
  Serial.print("f2 ");
}
void function_3() {
  Serial.println("f3");
}

Show one of these sketches.

Thank you for the replies and help! I'll try that, see what happens.

Again, thank you!

Do not use pin 0 or pin 1 for uses other than uploading your code.

Learn how to use arrays to make your code a lot shorter.

You need a state machine for your pattern which means removing all delays and unwinding all the for loops that contain delays.

This has quickly gotten over my head. For the time being, I'm going to try sort it with hardware. I have more than enuff 555's and 4017's to do it with.

Thanks for your help and direction!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.