Cycle led effects with push button?

Hi, so I’ve got some code working and I like the effects, this is a mix of my own tinkering with someone else’s code so instead of it just cycling through each effect in a loop I want to be able to change the effect with a push button or maybe a rotary encoder to select it. Currently, it does “work” but you kinda have to spam the button to get it to register in the little time it has before the effect just loops again. I thought maybe milis could fix this but I’m unsure how to implement that into the effects and rest of the code. I also thought I might be able to use a rotary encoder but I’m again unsure as to if that would fix this problem or not.

here’s my code currently that works the way I want except for the button cause you have to spam it.

#include <FastLED.h>
#define LED_PIN     4
#define NUM_LEDS    32
#define button 7

int state = 0;
int old = 0;
int buttonPoll = 0;

int strobo_1 = 30;
int strobo_2 = 80;
int strobo_3 = 50;
int strobo_4 = 100;

int freq_1 = 10;
int freq_2 = 30;
int freq_3 = 100;

int freq_pattern_1 = 40;

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  pinMode(button,INPUT);
}

void loop() {
 buttonPoll = digitalRead(button);
 if(buttonPoll == 1) {
 delay(50);
 buttonPoll = digitalRead(button);
 if(buttonPoll == 0) {
 state = old + 1;
 }
 }
 else {
 delay(100);
}

switch (state) {
 case 1: //effect 1
 bianco();
 delay(strobo_2);
 old = state;
 break;

 case 2: //effect 2
 mix_rwb();
 delay(strobo_2);
 old = state;
 break;

 case 3: //effect 3
  for (int i = 0; i <= 6; i++) {
    mix_rl_w_lr();
    delay(strobo_1);
  }
 old = state; 
 break;

 case 4: //effect 4
 for (int i = 0; i <= 6; i++) {
    rosso();
    delay (strobo_2);

    blu();
    delay(strobo_2);

    rosso();
    delay (strobo_2);

    blu();
    delay(strobo_2);
  }
 old = state; 
 break;

 case 5: //effect 5
 for (int i = 0; i <= 6; i++) {
    pattern_1();
 }
 old = state; 
 break;

 default: //default effect
 for (int i = 0; i <= 3; i++) {
    mix_rl_lr(); 
   delay(strobo_1);
  }
 old = 0;
 break;
 }
}

//effects

void rosso() {
  
  for (int i = 0; i <= 3; i++) {
       
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);
  leds[10]=CRGB (255,0,0);
  leds[11]=CRGB (255,0,0);
  leds[12]=CRGB (255,0,0);
  FastLED.show();
  delay(strobo_1);
  
  FastLED.clear ();
  delay(strobo_1);
  
  FastLED.show();
  delay(strobo_1);
  }
}


void bianco()  {

for (int i = 0; i <= 3; i++) {
  
  
  leds[13]=CRGB (255,255,255);
  leds[14]=CRGB (255,255,255);
  leds[15]=CRGB (255,255,255);
  leds[16]=CRGB (255,255,255);
  leds[17]=CRGB (255,255,255);
  leds[18]=CRGB (255,255,255);
  leds[19]=CRGB (255,255,255);

  FastLED.show();
  delay(strobo_1);
  
  FastLED.clear ();
  delay(strobo_1);
  
  FastLED.show();
  delay(strobo_1);
  
 } 
}


void blu()  {

for (int i = 0; i <= 3; i++) {
 
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);
  leds[30]=CRGB (0,0,255);
  leds[31]=CRGB (0,0,255);
  leds[32]=CRGB (0,0,255);


  FastLED.show();
  delay(strobo_1);
  
  FastLED.clear ();
  delay(strobo_1);
  
  FastLED.show();
  delay(strobo_1);
  
  }
}

void mix_rwb()  {

for (int i = 0; i <= 6; i++) {
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);
  
  leds[10]=CRGB (255,255,255);
  leds[11]=CRGB (255,255,255);
  leds[12]=CRGB (255,255,255);
  leds[13]=CRGB (255,255,255);
  leds[14]=CRGB (255,255,255);
  leds[15]=CRGB (255,255,255);
  leds[16]=CRGB (255,255,255);
  leds[17]=CRGB (255,255,255);
  leds[18]=CRGB (255,255,255);

  leds[19]=CRGB (0,0,255);
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);

  FastLED.show();
  delay(strobo_1);
  
  FastLED.clear ();
  delay(strobo_1);
  
  FastLED.show();
  delay(strobo_1);
  
  }
 
}


void mix_rb()  {

for (int i = 0; i <= 3; i++) {
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);

  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);

  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);

}

for (int i = 0; i <= 3; i++) {
  
  leds[19]=CRGB (0,0,255);
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);

  
  
  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);

  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);
  
  }
 
}



void mix_rl_lr()  {

 for (int i = 0; i <= 3; i++) {
  
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);

  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);
  leds[30]=CRGB (0,0,255);
  leds[31]=CRGB (0,0,255);
  leds[32]=CRGB (0,0,255);

  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);
}

 
 for (int i = 0; i <= 3; i++) {

  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (2550,0,0);
  leds[9]=CRGB (2550,0,0);
  leds[10]=CRGB (255,0,0);
  leds[11]=CRGB (2550,0,0);

  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  
  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);

  }
}




void mix_rl_w_lr()  {

 for (int i = 0; i <= 3; i++) {
  
  leds[0]=CRGB::Red;
  leds[1]=CRGB::Red;
  leds[2]=CRGB::Red;
  leds[3]=CRGB::Red;
  leds[4]=CRGB::Red;

  
  leds[10]=CRGB::White;
  leds[11]=CRGB::White;
  leds[12]=CRGB::White;
  leds[13]=CRGB::White;
  leds[14]=CRGB::White;
  
  leds[15]=CRGB::White;
  leds[16]=CRGB::White;
  leds[17]=CRGB::White;
  leds[18]=CRGB::White;

  leds[25]=CRGB::Blue;
  leds[26]=CRGB::Blue;
  leds[27]=CRGB::Blue;
  leds[28]=CRGB::Blue;
  leds[29]=CRGB::Blue;

  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);
}

 
 for (int i = 0; i <= 3; i++) {
  
  leds[5]=CRGB::Red;
  leds[6]=CRGB::Red;
  leds[7]=CRGB::Red;
  leds[8]=CRGB::Red;
  leds[9]=CRGB::Red;

  leds[10]=CRGB::Black;
  leds[11]=CRGB::Black;
  leds[12]=CRGB::Black;
  leds[13]=CRGB::Black;
  leds[14]=CRGB::Black;

  leds[15]=CRGB::Black;
  leds[16]=CRGB::Black;
  leds[17]=CRGB::Black;
  leds[18]=CRGB::Black;

  
    
  leds[19]=CRGB::Blue;
  leds[20]=CRGB::Blue;
  leds[21]=CRGB::Blue;
  leds[22]=CRGB::Blue;
  leds[23]=CRGB::Blue;
  
  FastLED.show();
  delay(strobo_1);
  FastLED.clear ();
  delay(strobo_1);

  }
}

void rosso_static() {  
       
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);

  FastLED.show();
  delay(strobo_3);
  
  FastLED.clear();
  delay(strobo_3);

}


void bianco_static()  {
 
  leds[10]=CRGB (255,255,255);
  leds[11]=CRGB (255,255,255);
  leds[12]=CRGB (255,255,255);
  leds[13]=CRGB (255,255,255);
  leds[14]=CRGB (255,255,255);
  leds[15]=CRGB (255,255,255);
  leds[16]=CRGB (255,255,255);
  leds[17]=CRGB (255,255,255);
  leds[18]=CRGB (255,255,255);

  FastLED.show();
  delay(strobo_3);
  
  FastLED.clear();
  delay(strobo_3);
    
}


void blu_static()  {

  leds[19]=CRGB (0,0,255);
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);

  FastLED.show();
  delay(strobo_3);
  
  FastLED.clear();
  delay(strobo_3);
  
}

void pattern_1()  {

  for (int i = 0; i <= 3; i++) {  
    
    leds[0]=CRGB (255,0,0);
    leds[1]=CRGB (255,0,0);
    leds[2]=CRGB (255,0,0);
    leds[3]=CRGB (255,0,0);
    leds[4]=CRGB (255,0,0);

    leds[25]=CRGB (0,0,255);
    leds[26]=CRGB (0,0,255);
    leds[27]=CRGB (0,0,255);
    leds[28]=CRGB (0,0,255);
    leds[29]=CRGB (0,0,255);

    FastLED.show();
    delay(freq_pattern_1);
    FastLED.clear ();
    delay(freq_pattern_1);
    }

  for (int i = 0; i <= 3; i++) {
  
    leds[5]=CRGB (255,0,0);
    leds[6]=CRGB (255,0,0);
    leds[7]=CRGB (255,0,0);
    leds[8]=CRGB (2550,0,0);
    leds[9]=CRGB (2550,0,0);
    
    leds[19]=CRGB (0,0,255);
    leds[20]=CRGB (0,0,255);
    leds[21]=CRGB (0,0,255);
    leds[22]=CRGB (0,0,255);
    leds[23]=CRGB (0,0,255);
  
    FastLED.show();
    delay(freq_pattern_1);
    FastLED.clear ();
    delay(freq_pattern_1); 
    }
}

void pattern_2()  {

  for (int i = 0; i <= 3; i++) {  
    
    leds[0]=CRGB (255,0,0);
    leds[1]=CRGB (255,0,0);
    leds[2]=CRGB (255,0,0);
    leds[3]=CRGB (255,0,0);
    leds[4]=CRGB (255,0,0);

    leds[25]=CRGB (0,0,255);
    leds[26]=CRGB (0,0,255);
    leds[27]=CRGB (0,0,255);
    leds[28]=CRGB (0,0,255);
    leds[29]=CRGB (0,0,255);

    FastLED.show();
    delay(freq_pattern_1);
    FastLED.clear ();
    delay(freq_pattern_1);
    }

 
  for (int i = 0; i <= 3; i++) {
  
    leds[5]=CRGB (255,0,0);
    leds[6]=CRGB (255,0,0);
    leds[7]=CRGB (255,0,0);
    leds[8]=CRGB (2550,0,0);
    leds[9]=CRGB (2550,0,0);
      
    leds[19]=CRGB (0,0,255);
    leds[20]=CRGB (0,0,255);
    leds[21]=CRGB (0,0,255);
    leds[22]=CRGB (0,0,255);
    leds[23]=CRGB (0,0,255);
  
    FastLED.show();
    delay(freq_pattern_1);
    FastLED.clear ();
    delay(freq_pattern_1); 
    }
   
}

void white_blink() {

  for (int i = 0; i <= 3; i++) {
    
    //leds[10]=CRGB (255,255,255);
    //leds[11]=CRGB (255,255,255);
    //leds[12]=CRGB (255,255,255);
   
    leds[13]=CRGB (255,255,255);
    leds[14]=CRGB (255,255,255);
    leds[15]=CRGB (255,255,255);
    
    //leds[16]=CRGB (255,255,255);
    //leds[17]=CRGB (255,255,255);
    //leds[18]=CRGB (255,255,255);
    
    FastLED.show();
    delay(freq_pattern_1);
    FastLED.clear ();
    delay(freq_pattern_1); 

    leds[10]=CRGB (255,255,255);
    leds[11]=CRGB (255,255,255);
    leds[12]=CRGB (255,255,255);
   
    //leds[13]=CRGB (255,255,255);
    //leds[14]=CRGB (255,255,255);
    //leds[15]=CRGB (255,255,255);
    
    leds[16]=CRGB (255,255,255);
    leds[17]=CRGB (255,255,255);
    leds[18]=CRGB (255,255,255);


    FastLED.show();
    delay(freq_pattern_1);
    FastLED.clear ();
    delay(freq_pattern_1); 
    
  }

}

I did a low level flight over your sketch. I find it is extremely difficult to insert the desired functionality of a control, however designed, into the existing sketch. The multiple execution of the delay() function blocks the continuous program execution so that a “parallel” operation is not possible.
What now?
Study the IPO model, the use of FSM, timers and structured data design with OOP.

You could also use an interrupt to handle the button. That way you do not need to get rid of all the discust… I mean delay…!! :stuck_out_tongue:

Look at this thread

I think this, possibly expanded with setjmp/longjmp might be another inelegant but workable kludge.

But sooner later take @paulpaulson’s advice. Once you get the hang of it, you’ll be empowered by the technique, and it actually makes for much more readable as well as flexible code.

a7

1 Like

that will never interrupt the flow of the running code execution, willn´t?

I doubted for some reason that setjmp/longjmp would be available, here’s a complete example.

/* setjmp example */

# include <setjmp.h>

static jmp_buf buf;

void second() {
	Serial.println("second\n"); // prints
	longjmp(buf, 1);            // jumps back to where setjmp was called - making setjmp now return 1
}

void first() {
	second();
	Serial.println("first");    // does not print
}

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

void loop() {
	if (!setjmp(buf))
		first();                   // when executed, setjmp returned 0
	else                           // when longjmp jumps back, setjmp returns 1
		Serial.println("loop!");   // prints

  for (; ; );
}

Google setjmp, I am too tired right now to combine this with a myDelay kludge, but I am confidant it could be made to work.

An inelegant kludge.

a7

No, but it will not go dark in the delay() - every myDelay will delay and also look for a signal to do otherwise.

It just depends on

    if (myDelay(100)) return;

to where you are returning. Which is what made me think of non-local goto mechanism of setjmp/longjmp.

a7

Hello,
that is similar to my homebrewed solution.

Thank you for the advice and I figured out a solution with the help of another person on a different forum site. I’m definitely going to keep this in mind for when i do my next project!

I implemented this and changed all the delays to it and it works just great!

void delay_bt(uint32_t ms)
{
uint32_t start_ms = millis();
uint32_t bt_press_time = 0;
while(start_ms + ms > millis())
{
if(digitalRead(button) && bt_press_time == 0) bt_press_time = millis();
else
{
if(bt_press_time > 0 && millis() - bt_press_time > 10) state = old + 1; //debouncing period of 10 ms
bt_press_time = 0;
}
}
if(bt_press_time > 0) state = old + 1; //in case if delay period ends before debouncing period
}

entire code that does exactly what I need

#include <FastLED.h>
#define LED_PIN     4
#define NUM_LEDS    32
#define button 7

int state = 0;
int old = 0;
int buttonPoll = 0;

int strobo_1 = 30;
int strobo_2 = 80;
int strobo_3 = 50;
int strobo_4 = 100;

int freq_1 = 10;
int freq_2 = 30;
int freq_3 = 100;

int freq_pattern_1 = 40;

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  pinMode(button,INPUT);
}

void loop() {
 buttonPoll = digitalRead(button);
 if(buttonPoll == 1) {
 delay_bt(50);
 buttonPoll = digitalRead(button);
 if(buttonPoll == 0) {
 state = old + 1;
 }
 }
 else {
 delay_bt(100);
}

switch (state) {
 case 1: //effect 1
 bianco();
 delay_bt(strobo_2);
 old = state;
 break;

 case 2: //effect 2
 mix_rwb();
 delay_bt(strobo_2);
 old = state;
 break;

 case 3: //effect 3
  for (int i = 0; i <= 6; i++) {
    mix_rl_w_lr();
    delay_bt(strobo_1);
  }
 old = state; 
 break;

 case 4: //effect 4
 for (int i = 0; i <= 6; i++) {
    rosso();
    delay_bt (strobo_2);

    blu();
    delay_bt(strobo_2);

    rosso();
    delay_bt (strobo_2);

    blu();
    delay_bt(strobo_2);
  }
 old = state; 
 break;

 case 5: //effect 5
 for (int i = 0; i <= 6; i++) {
    pattern_1();
 }
 old = state; 
 break;

 default: //default effect
 for (int i = 0; i <= 3; i++) {
    mix_rl_lr(); 
   delay_bt(strobo_1);
  }
 old = 0;
 break;
 }
}

//button checker

void delay_bt(uint32_t ms)
{
uint32_t start_ms = millis();
uint32_t bt_press_time = 0;
while(start_ms + ms > millis())
{
if(digitalRead(button) && bt_press_time == 0) bt_press_time = millis();
else
{
if(bt_press_time > 0 && millis() - bt_press_time > 10) state = old + 1; //debouncing period of 10 ms
bt_press_time = 0;
}
}
if(bt_press_time > 0) state = old + 1; //in case if delay period ends before debouncing period
}

//effects

void rosso() {
  
  for (int i = 0; i <= 3; i++) {
       
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);
  leds[10]=CRGB (255,0,0);
  leds[11]=CRGB (255,0,0);
  leds[12]=CRGB (255,0,0);
  FastLED.show();
  delay_bt(strobo_1);
  
  FastLED.clear ();
  delay_bt(strobo_1);
  
  FastLED.show();
  delay_bt(strobo_1);
  }
}


void bianco()  {

for (int i = 0; i <= 3; i++) {
  
  
  leds[13]=CRGB (255,255,255);
  leds[14]=CRGB (255,255,255);
  leds[15]=CRGB (255,255,255);
  leds[16]=CRGB (255,255,255);
  leds[17]=CRGB (255,255,255);
  leds[18]=CRGB (255,255,255);
  leds[19]=CRGB (255,255,255);

  FastLED.show();
  delay_bt(strobo_1);
  
  FastLED.clear ();
  delay_bt(strobo_1);
  
  FastLED.show();
  delay_bt(strobo_1);
  
 } 
}


void blu()  {

for (int i = 0; i <= 3; i++) {
 
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);
  leds[30]=CRGB (0,0,255);
  leds[31]=CRGB (0,0,255);
  leds[32]=CRGB (0,0,255);


  FastLED.show();
  delay_bt(strobo_1);
  
  FastLED.clear ();
  delay_bt(strobo_1);
  
  FastLED.show();
  delay_bt(strobo_1);
  
  }
}

void mix_rwb()  {

for (int i = 0; i <= 6; i++) {
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);
  
  leds[10]=CRGB (255,255,255);
  leds[11]=CRGB (255,255,255);
  leds[12]=CRGB (255,255,255);
  leds[13]=CRGB (255,255,255);
  leds[14]=CRGB (255,255,255);
  leds[15]=CRGB (255,255,255);
  leds[16]=CRGB (255,255,255);
  leds[17]=CRGB (255,255,255);
  leds[18]=CRGB (255,255,255);

  leds[19]=CRGB (0,0,255);
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);

  FastLED.show();
  delay_bt(strobo_1);
  
  FastLED.clear ();
  delay_bt(strobo_1);
  
  FastLED.show();
  delay_bt(strobo_1);
  
  }
 
}


void mix_rb()  {

for (int i = 0; i <= 3; i++) {
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);

  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);

  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);

}

for (int i = 0; i <= 3; i++) {
  
  leds[19]=CRGB (0,0,255);
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);

  
  
  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);

  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);
  
  }
 
}



void mix_rl_lr()  {

 for (int i = 0; i <= 3; i++) {
  
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);

  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);
  leds[30]=CRGB (0,0,255);
  leds[31]=CRGB (0,0,255);
  leds[32]=CRGB (0,0,255);

  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);
}

 
 for (int i = 0; i <= 3; i++) {

  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (2550,0,0);
  leds[9]=CRGB (2550,0,0);
  leds[10]=CRGB (255,0,0);
  leds[11]=CRGB (2550,0,0);

  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  
  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);

  }
}




void mix_rl_w_lr()  {

 for (int i = 0; i <= 3; i++) {
  
  leds[0]=CRGB::Red;
  leds[1]=CRGB::Red;
  leds[2]=CRGB::Red;
  leds[3]=CRGB::Red;
  leds[4]=CRGB::Red;

  
  leds[10]=CRGB::White;
  leds[11]=CRGB::White;
  leds[12]=CRGB::White;
  leds[13]=CRGB::White;
  leds[14]=CRGB::White;
  
  leds[15]=CRGB::White;
  leds[16]=CRGB::White;
  leds[17]=CRGB::White;
  leds[18]=CRGB::White;

  leds[25]=CRGB::Blue;
  leds[26]=CRGB::Blue;
  leds[27]=CRGB::Blue;
  leds[28]=CRGB::Blue;
  leds[29]=CRGB::Blue;

  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);
}

 
 for (int i = 0; i <= 3; i++) {
  
  leds[5]=CRGB::Red;
  leds[6]=CRGB::Red;
  leds[7]=CRGB::Red;
  leds[8]=CRGB::Red;
  leds[9]=CRGB::Red;

  leds[10]=CRGB::Black;
  leds[11]=CRGB::Black;
  leds[12]=CRGB::Black;
  leds[13]=CRGB::Black;
  leds[14]=CRGB::Black;

  leds[15]=CRGB::Black;
  leds[16]=CRGB::Black;
  leds[17]=CRGB::Black;
  leds[18]=CRGB::Black;

  
    
  leds[19]=CRGB::Blue;
  leds[20]=CRGB::Blue;
  leds[21]=CRGB::Blue;
  leds[22]=CRGB::Blue;
  leds[23]=CRGB::Blue;
  
  FastLED.show();
  delay_bt(strobo_1);
  FastLED.clear ();
  delay_bt(strobo_1);

  }
}

void rosso_static() {  
       
  leds[0]=CRGB (255,0,0);
  leds[1]=CRGB (255,0,0);
  leds[2]=CRGB (255,0,0);
  leds[3]=CRGB (255,0,0);
  leds[4]=CRGB (255,0,0);
  leds[5]=CRGB (255,0,0);
  leds[6]=CRGB (255,0,0);
  leds[7]=CRGB (255,0,0);
  leds[8]=CRGB (255,0,0);
  leds[9]=CRGB (255,0,0);

  FastLED.show();
  delay_bt(strobo_3);
  
  FastLED.clear();
  delay_bt(strobo_3);

}


void bianco_static()  {
 
  leds[10]=CRGB (255,255,255);
  leds[11]=CRGB (255,255,255);
  leds[12]=CRGB (255,255,255);
  leds[13]=CRGB (255,255,255);
  leds[14]=CRGB (255,255,255);
  leds[15]=CRGB (255,255,255);
  leds[16]=CRGB (255,255,255);
  leds[17]=CRGB (255,255,255);
  leds[18]=CRGB (255,255,255);

  FastLED.show();
  delay_bt(strobo_3);
  
  FastLED.clear();
  delay_bt(strobo_3);
    
}


void blu_static()  {

  leds[19]=CRGB (0,0,255);
  leds[20]=CRGB (0,0,255);
  leds[21]=CRGB (0,0,255);
  leds[22]=CRGB (0,0,255);
  leds[23]=CRGB (0,0,255);
  leds[24]=CRGB (0,0,255);
  leds[25]=CRGB (0,0,255);
  leds[26]=CRGB (0,0,255);
  leds[27]=CRGB (0,0,255);
  leds[28]=CRGB (0,0,255);
  leds[29]=CRGB (0,0,255);

  FastLED.show();
  delay_bt(strobo_3);
  
  FastLED.clear();
  delay_bt(strobo_3);
  
}

void pattern_1()  {

  for (int i = 0; i <= 3; i++) {  
    
    leds[0]=CRGB (255,0,0);
    leds[1]=CRGB (255,0,0);
    leds[2]=CRGB (255,0,0);
    leds[3]=CRGB (255,0,0);
    leds[4]=CRGB (255,0,0);

    leds[25]=CRGB (0,0,255);
    leds[26]=CRGB (0,0,255);
    leds[27]=CRGB (0,0,255);
    leds[28]=CRGB (0,0,255);
    leds[29]=CRGB (0,0,255);

    FastLED.show();
    delay_bt(freq_pattern_1);
    FastLED.clear ();
    delay_bt(freq_pattern_1);
    }

  for (int i = 0; i <= 3; i++) {
  
    leds[5]=CRGB (255,0,0);
    leds[6]=CRGB (255,0,0);
    leds[7]=CRGB (255,0,0);
    leds[8]=CRGB (2550,0,0);
    leds[9]=CRGB (2550,0,0);
    
    leds[19]=CRGB (0,0,255);
    leds[20]=CRGB (0,0,255);
    leds[21]=CRGB (0,0,255);
    leds[22]=CRGB (0,0,255);
    leds[23]=CRGB (0,0,255);
  
    FastLED.show();
    delay_bt(freq_pattern_1);
    FastLED.clear ();
    delay_bt(freq_pattern_1); 
    }
}

void pattern_2()  {

  for (int i = 0; i <= 3; i++) {  
    
    leds[0]=CRGB (255,0,0);
    leds[1]=CRGB (255,0,0);
    leds[2]=CRGB (255,0,0);
    leds[3]=CRGB (255,0,0);
    leds[4]=CRGB (255,0,0);

    leds[25]=CRGB (0,0,255);
    leds[26]=CRGB (0,0,255);
    leds[27]=CRGB (0,0,255);
    leds[28]=CRGB (0,0,255);
    leds[29]=CRGB (0,0,255);

    FastLED.show();
    delay_bt(freq_pattern_1);
    FastLED.clear ();
    delay_bt(freq_pattern_1);
    }

 
  for (int i = 0; i <= 3; i++) {
  
    leds[5]=CRGB (255,0,0);
    leds[6]=CRGB (255,0,0);
    leds[7]=CRGB (255,0,0);
    leds[8]=CRGB (2550,0,0);
    leds[9]=CRGB (2550,0,0);
      
    leds[19]=CRGB (0,0,255);
    leds[20]=CRGB (0,0,255);
    leds[21]=CRGB (0,0,255);
    leds[22]=CRGB (0,0,255);
    leds[23]=CRGB (0,0,255);
  
    FastLED.show();
    delay_bt(freq_pattern_1);
    FastLED.clear ();
    delay_bt(freq_pattern_1); 
    }
   
}

void white_blink() {

  for (int i = 0; i <= 3; i++) {
    
    //leds[10]=CRGB (255,255,255);
    //leds[11]=CRGB (255,255,255);
    //leds[12]=CRGB (255,255,255);
   
    leds[13]=CRGB (255,255,255);
    leds[14]=CRGB (255,255,255);
    leds[15]=CRGB (255,255,255);
    
    //leds[16]=CRGB (255,255,255);
    //leds[17]=CRGB (255,255,255);
    //leds[18]=CRGB (255,255,255);
    
    FastLED.show();
    delay_bt(freq_pattern_1);
    FastLED.clear ();
    delay_bt(freq_pattern_1); 

    leds[10]=CRGB (255,255,255);
    leds[11]=CRGB (255,255,255);
    leds[12]=CRGB (255,255,255);
   
    //leds[13]=CRGB (255,255,255);
    //leds[14]=CRGB (255,255,255);
    //leds[15]=CRGB (255,255,255);
    
    leds[16]=CRGB (255,255,255);
    leds[17]=CRGB (255,255,255);
    leds[18]=CRGB (255,255,255);


    FastLED.show();
    delay_bt(freq_pattern_1);
    FastLED.clear ();
    delay_bt(freq_pattern_1); 
    
  }

}

haha yeah, I know, I hate delays but I’ve been too lazy to study and learn milis but that came back to bite me in the but when I decided to try and “quickly” make this last night. Definitely going to teach myself it now so im not in this situation again!

@IcyBlade we’ve all had to learn this, and we’ve all had opportunity to, um, cheat with a clever kludge.

In delay_bt, change

while(start_ms + ms > millis())

to

 while (millis() - start_ms < ms) {

to avoid a problem there could be if you let this run for 49 days or something like that.

The dreaded but tots avoidable millis() rollover.

a7

Okay, Thank you for letting me know! I’ll change that up.