Making one loop of code stop and another start.

Hey all, I’m relatively new to this. basically I want to have my LEDs run around in a circle once a PIR sensor goes off (already have that figured out) but then after they do this for “x” amount of time I want them to start a completely different pattern without ever going back to the first pattern. Any ideas or help would be greatly appreciated.

#include <Adafruit_NeoPixel.h>

#include <FastLED.h>

#define DATA_PIN 11
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 150
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 120
int pirStat = 0;
int onePos = 1;
int twoPos = 75;
byte oneDir = 0;
byte twoDir = 0;
CRGB leds[NUM_LEDS];

void setup() {
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS);
pinMode(2,INPUT);
pinMode(11,OUTPUT);

}

void loop() {

pirStat =digitalRead(2);
if (pirStat == HIGH) {
leds[onePos]=CRGB(0,255,127);
leds[max(onePos -1,0)]=CRGB(0,255,127);
leds[min(onePos+1,NUM_LEDS - 1)]=CRGB(0,255,127);

leds[twoPos]=CRGB(0,255,255);
leds[max(twoPos -1,0)]=CRGB(0,255,255);
leds[min(twoPos+1,NUM_LEDS-1)]=CRGB(0,255,255);

FastLED.show();
delay(10);

leds[onePos]=CRGB(0,0,0);
leds[max(onePos -1,0)]=CRGB(0,0,0);
leds[min(onePos+1,NUM_LEDS - 1)]=CRGB(0,0,0);

leds[twoPos]=CRGB(0,0,0);
leds[max(twoPos -1,0)]=CRGB(0,0,0);
leds[min(twoPos+1,NUM_LEDS-1)]=CRGB(0,0,0);

if (oneDir == 0) {
onePos += 1;
if (onePos >= NUM_LEDS) {
onePos = 0;
}
}

if (twoDir == 0) {
twoPos += 1;
if (twoPos >= NUM_LEDS) {
twoPos = 0;

}
}
}
}

Please post code the way described in the first topics, "How to use forrum" etc.

What is working, what is not working? Your description doesn't make me understand what's it all about.

Sorry about the code, and what I am trying to do is after this code runs, I want it to stop and then start a new pattern/design/code/whatever you want to call it and it never go back to this code.

So for example I want to run the code I already posted:

#include <Adafruit_NeoPixel.h>

#include <FastLED.h>





#define DATA_PIN    11
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS    150 
#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120
int pirStat = 0;
int onePos = 1;
int twoPos = 75;
byte oneDir = 0;
byte twoDir = 0;
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS);
pinMode(2,INPUT);
pinMode(11,OUTPUT);

}

void loop() {

pirStat =digitalRead(2);
if (pirStat == HIGH) {
 leds[onePos]=CRGB(0,255,127);
 leds[max(onePos -1,0)]=CRGB(0,255,127);
 leds[min(onePos+1,NUM_LEDS - 1)]=CRGB(0,255,127);

 leds[twoPos]=CRGB(0,255,255);
 leds[max(twoPos -1,0)]=CRGB(0,255,255);
 leds[min(twoPos+1,NUM_LEDS-1)]=CRGB(0,255,255);
 
  FastLED.show();
  delay(10);

  leds[onePos]=CRGB(0,0,0);
 leds[max(onePos -1,0)]=CRGB(0,0,0);
 leds[min(onePos+1,NUM_LEDS - 1)]=CRGB(0,0,0);

 leds[twoPos]=CRGB(0,0,0);
 leds[max(twoPos -1,0)]=CRGB(0,0,0);
 leds[min(twoPos+1,NUM_LEDS-1)]=CRGB(0,0,0);


  if (oneDir == 0) {     
    onePos += 1;
    if (onePos >= NUM_LEDS) {
      onePos = 0;
    }
  }

       if (twoDir == 0) {    
    twoPos += 1;
    if (twoPos >= NUM_LEDS) {
      twoPos = 0;
     
     }
   }
 }
}

After this code runs for 30 seconds I want all the lights to stop and for this code to run:

void loop(){

leds[0]=CRGB::Red;
FastLED.show();

and keep that light on indefinitely and never go back to having lights go in a circle in the first code.

No problem. Collect all the code in the first loop() and make it a function, "Code1". Do the same to the second code in that loop(), name it "Code2".
Now Your new loop() loks like:

void loop(void){
  Code1();
  Code2();
}

Using @Railroader's suggestion as a start point, create a boolean flag firstRun and initialize it to true. In loop(), if firstRun is true call Code1() else call Code2(). The last thing Code1() does before it finishes is set the flag to false.

Thank you guys! I appreciate your help, it is frustrating to want such a simple thing and the answer is simple but because I don't fully know the language I can't put it into the code. Hopefully I can have this project done tomorrow with this new knowledge.