Multiple functions in loop function[SOLVED]

I have a problem trying to make a void function that will go through all of my functions,and will run every of that function for specified duration of time,10 second would be good,my code has a button that alows me to switch betwen functions on changed state,but i would like to make one more function that would do that automaticly every 10 second,and i would enter that function with a button like all the other ones i already have. For now my all function only freezes the leds
This is my code

#include <FastLED.h>
int pushButton = 8;
int newvalue;
unsigned int oldvalue = newvalue = 0;
#define DATA_PIN    10
#define DATA_PIN1    6
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    64
#define NUM_LEDS2    40
#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  220
CRGB leds[NUM_LEDS];

void setup(){
  pinMode(pushButton, INPUT);
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.addLeds<LED_TYPE,DATA_PIN1,COLOR_ORDER>(leds, NUM_LEDS2).setCorrection(TypicalLEDStrip);
}

typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { all, pacifica_loop, pride, prideP, rainbow, rainbowWithGlitter, confetti, confetti_GB, sinelon, sinelon_P, juggle, juggle_P, bpm };
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns

CRGBPalette16 pacifica_palette_1 = 
    { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117, 
      0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x14554B, 0x28AA50 };
CRGBPalette16 pacifica_palette_2 = 
    { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117, 
      0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x0C5F52, 0x19BE5F };
CRGBPalette16 pacifica_palette_3 = 
    { 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33, 
      0x000E39, 0x001040, 0x001450, 0x001860, 0x001C70, 0x002080, 0x1040BF, 0x2060FF };
  
void loop(){
  newvalue = digitalRead(pushButton); 
  gPatterns[gCurrentPatternNumber]();
  FastLED.show();  
  FastLED.delay(1000/FRAMES_PER_SECOND); 
  EVERY_N_MILLISECONDS( 60 ) { gHue++; } // slowly cycle the "base color" through the rainbow
    if (newvalue != oldvalue){
      nextPattern();
      oldvalue = newvalue;
  }
        #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
}

void nextPattern(){
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void all(){
 pride(); 
 prideP();
 rainbow();
 rainbowWithGlitter();
 confetti();
 confetti_GB();
 sinelon();
 sinelon_P();
 juggle();
 juggle_P();
 bpm();
}

void pride(){
  static uint16_t sPseudotime = 0;
  static uint16_t sLastMillis = 0;
  static uint16_t sHue16 = 0;
  uint8_t sat8 = beatsin88( 87, 220, 250);
  uint8_t brightdepth = beatsin88( 341, 96, 224);
  uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
  uint8_t msmultiplier = beatsin88(147, 23, 60);
  uint16_t hue16 = sHue16;//gHue * 256;
  uint16_t hueinc16 = beatsin88(113, 1, 3000);
  uint16_t ms = millis();
  uint16_t deltams = ms - sLastMillis ;
  sLastMillis  = ms;
  sPseudotime += deltams * msmultiplier;
  sHue16 += deltams * beatsin88( 400, 5,9);
  uint16_t brightnesstheta16 = sPseudotime;
    for( uint16_t i = 0 ; i < NUM_LEDS; i++){
      hue16 += hueinc16;
      uint8_t hue8 = hue16 / 256;
      brightnesstheta16  += brightnessthetainc16;
      uint16_t b16 = sin16( brightnesstheta16  ) + 32768;
      uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
      uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
      bri8 += (255 - brightdepth);
      CRGB newcolor = CHSV( hue8, sat8, bri8);
      uint16_t pixelnumber = i;
      pixelnumber = (NUM_LEDS-1) - pixelnumber;
      nblend( leds[pixelnumber], newcolor, 64);
  }
}

void prideP(){
  static uint16_t sPseudotime = 0;
  static uint16_t sLastMillis = 0;
  static uint16_t sHue16 = 0;
  uint8_t sat8 = beatsin88( 87, 220, 250);
  uint8_t brightdepth = beatsin88( 341, 96, 224);
  uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
  uint8_t msmultiplier = beatsin88(147, 23, 60);
  uint16_t hue16 = sHue16;//gHue * 256;
  uint16_t hueinc16 = beatsin88(113, 1, 3000);
  uint16_t ms = millis();
  uint16_t deltams = ms - sLastMillis ;
  sLastMillis  = ms;
  sPseudotime += deltams * msmultiplier;
  sHue16 += deltams * beatsin88( 400, 5,9);
  uint16_t brightnesstheta16 = sPseudotime;
    for( uint16_t i = 0 ; i < NUM_LEDS; i++){
      hue16 += hueinc16;
      uint8_t hue8 = 195;
      brightnesstheta16  += brightnessthetainc16;
      uint16_t b16 = sin16( brightnesstheta16  ) + 32768;
      uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
      uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
      bri8 += (255 - brightdepth);
      CRGB newcolor = CHSV( hue8, sat8, bri8);
      uint16_t pixelnumber = i;
      pixelnumber = (NUM_LEDS-1) - pixelnumber;
      nblend( leds[pixelnumber], newcolor, 64);
  }
}

void rainbow(){
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter(){
  rainbow();
  addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter){
  if( random8() < chanceOfGlitter){
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

void confetti(){
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void confetti_GB(){
  uint8_t p = 64;
  fadeToBlackBy( leds, NUM_LEDS, 10);
    if(random8(100) < p){
      int pos = random16(NUM_LEDS);
      uint8_t hue = random8(2);  
        if (hue == 0){  
          hue = random8(185,190);  
      } 
        else{ 
      hue = random8(190,200); 
    }
    leds[pos] += CHSV( hue, random8(200,240), 255);
  }
}

void sinelon()
{
  fadeToBlackBy( leds, NUM_LEDS, 20);
  fadeToBlackBy( leds, NUM_LEDS2, 20);
  int pos = beatsin16( 10, 0, NUM_LEDS-1);
  int pos2 = beatsin16( 10, 0, NUM_LEDS2-1);
  leds[pos] += CHSV( gHue, 255, 192);
  leds[pos2] += CHSV( gHue, 255, 192);
}

void sinelon_P(){
  int Hue = 185;//boja piksela
  fadeToBlackBy( leds, NUM_LEDS, 20);
  fadeToBlackBy( leds, NUM_LEDS2, 20);
  int pos = beatsin16( 10, 0, NUM_LEDS-1);
  int pos2 = beatsin16( 10, 0, NUM_LEDS2-1);
  leds[pos] += CHSV( Hue, 255, 192);
  leds[pos2] += CHSV( Hue, 255, 192);
}

void bpm(){
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
    for( int i = 0; i < NUM_LEDS; i++) { //9948
      leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  }
}

void juggle(){
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 0;
    for( int i = 0; i < 8; i++) {
      leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
      dothue += 32;
  }
}

void juggle_P() {
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 185;
    for( int i = 0; i < 8; i++){
      leds[beatsin16( i+7, 0, NUM_LEDS-1)] |= CHSV(dothue, 200, 255);
  }
}
void all()
{
  pacifica_loop;
  pride;
  prideP;
  rainbow;
  rainbowWithGlitter;
  confetti;
  confetti_GB;
  sinelon;
  sinelon_P;
  juggle;
  juggle_P;
  bpm;
}

This function is NOT calling any functions. Function calls ALWAYS have ().

None of your functions have a mechanism to run for some defined amount of time. They all execute one iteration, regardless of how long that takes, and then get called again.

It's not really clear, given the way the code is written, just what you want to do, or if that is even possible.

I can try to explain better,like this i switch betwen functions with button,i want to keep that,but i want to make this all function() funcionable :D,when i go through all pattern list,all function () trys to run too,but it doesnt work,i want when it enters all function,to stay in it until i press the button again,and i want while it is in it to switch betwen all my other functions,and that every of them works for some time

Is your "period" button broken?

Paul

No but i dont know how to embed it in this code,i barely made it work like this,i just copy pasted,and did few minor changes,so it looks too complicated to figure out Everything except void all() works fine

Hi PaulS, nice to see you are still six feet above the bottom.

Have a look at how the code is organised in functions in Planning and Implementing a Program

…R

I did,i tried to use it on my code,but no luck,thanks for guidance anyways

I'm still confused what the question is.

Hi, DO NOT GO BACK and edit old posts. If you have changed your code, post it in a new post. By changing your first posts code you have made this thread difficult for anyone else to follow if they have a similar problem.

What model Arduino are you using? How have you got your button wired?

Thanks... Tom... :)

Kristijan1392: I did,i tried to use it on my code,but no luck,thanks for guidance anyways

If you post the code that represents your best attempt I will try to help. If I can't see exactly what you did I can't help. You may just have made a small mistake.

...R

I used arduino nano,and i used pull down resistor to connect the button,one side conected to 5v dc,other to digital pin on arduino and through resistor to ground,button works fine,this is the problem,let me explain on some example,lets say christmas lights,they have multiple programs for leds how to glow,and one of those programs goes through all other ones,reapets all of them,while other ones just repeat them self,i have made the other ones,i just need that one that will go through all my programs,and repeat that until i switch it with button to just one that will repeat it self,sorry if i am not good at explainig

void all()
{
  pacifica_loop();//run this 10 seconds than after that
  pride(); //run this 10 seconds than afther that
  prideP();//run this 10 seconds than afther that
  rainbow();//run this 10 seconds than afther that
  rainbowWithGlitter();//run this 10 seconds than afther that
  confetti();//run this 10 seconds than afther that
  confetti_GB();//run this 10 seconds than afther that
  sinelon();//run this 10 seconds than afther that
  sinelon_P();//run this 10 seconds than afther that
  juggle();//run this 10 seconds than afther that
  juggle_P();//run this 10 seconds than afther that
  bpm();//run this 10 seconds than afther that go bac to pacifica_loop(); and all over
}

this is what i need help with

Kristijan1392: this is what i need help with

You need to tell us what it actually does when you run it and what want it to do that is different.

Also, please always post a complete program.

...R

i am sorry,now when i run it my main void loop goes trough all void functions,it starts with void all,which does nothing,than when i change button state it goes to pacifica_loop,after i change it again to pride,and so on until it goes back to all loop again,which again does nothing,my switching function for button is ok,all my other functions are ok,only void all is not working,if i put delay it wont work and i wont be able to change function until all delays have passed,i want when it is in void all to go through all functions and to run every of them for 10 seconds as i wrote,but i dont know how to achieve that

want when it is in void all to go through all functions and to run every of them for 10 seconds as i wrote

YOU need to write all the functions that all() calls to take a parameter that defines how long they are to run, and then make them return when that time is up.

There are no magic bullets.

Kristijan1392:
i am sorry,now when i run it my main void loop goes trough all void functions,it starts with void all,which does nothing,

You have not posted the complete program - as requested in Reply #13

…R

Yes Paul,but how do i do that,what parameter do i add,is it a counter or something like that,robin all code is on begining

how do i do that

That depends on what the function does.

what parameter do i add

One that defines how long the function should execute for.

Kristijan1392: void all() {   pacifica_loop();//run this 10 seconds than after that   pride(); //run this 10 seconds than afther that   prideP();//run this 10 seconds than afther that   rainbow();//run this 10 seconds than afther that   rainbowWithGlitter();//run this 10 seconds than afther that   confetti();//run this 10 seconds than afther that   confetti_GB();//run this 10 seconds than afther that   sinelon();//run this 10 seconds than afther that   sinelon_P();//run this 10 seconds than afther that   juggle();//run this 10 seconds than afther that   juggle_P();//run this 10 seconds than afther that   bpm();//run this 10 seconds than afther that go bac to pacifica_loop(); and all over }

this is what i need help with

This is what it should do