multiple patterns using WS2812FX

Having some issue understanding how to use the WS2812FX library pre-programmed functions. Checked kitsurfer1404's GitHub site for WS2812FX and read the README & user guide file in the library but did not find the solution to my problem.

I want to cycle through different modes with a button. I can cycle through different cases with the code below, but the patterns do not display correctly.

case 0: displays static rainbow across pixel strip
case 1: static red LED every third LED
case 2: static pair of red and green LEDs (2x red, 2x green,...)
case 3: first 3 lights turn white
case 4: group of 5 red LEDs randomly appear/disappear on strip
case 5: all LEDs static red with a few random flickers of white/pink
case 6: first LED red, all others off
case 7: all LEDs are flickering white with hints of color
case 8: first LED red followed by 2 off LEDs and rest of strip has random static LED colors
case 9: first LED red, all others off

What changes do I need to make to the code?
Can I use switch/case with WS2812FX?

/* 
Cycle through different patterns using a button on Arduino Pro Mini ATMega328P (5V, 16MHz). 1000uF capacitor connected across VCC & GND of NeoPixel strip, and a 330ohm resistor in series with Data In and pin 6.  Pin 2 pulled HIGH with button connected that pulls LOW when pressed.
*/  

#include <WS2812FX.h>

#define LED_COUNT 26      // Number of WS2812B LEDs
#define LED_PIN 6         // Pin connected to Data In (DIN)
const byte button = 2;          // Button pin to GND (LOW) when pressed
int showType = 0;
bool lastReading = HIGH;  // Variable to store last button state
bool reading = HIGH;      // Variable to store current button state
unsigned long patternInterval = 20; // time between steps in the pattern
unsigned long lastUpdate = 0;        // for millis() when last update occurred

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() 
{
  pinMode(button, INPUT_PULLUP);  // Pull pin HIGH
  pinMode(LED_PIN, OUTPUT);       // Set DIN pin as OUTPUT
  
  ws2812fx.init();                // Initialize WS2812FX library
  ws2812fx.setBrightness(64);     // Brightness 0-255 [black to blinding]
  ws2812fx.setSpeed(1000);        // Speed 10-5000 [fast to slow]
  ws2812fx.start();               // Start WS2812FX library
}

void loop() 
{
  ws2812fx.service();  
  
  reading = digitalRead(button);
  
  // Check if button pressed
  if (reading == LOW && lastReading == HIGH)
  {
    lastUpdate = millis();
    showType++ ;        // Switch to next case
    if (showType >= 10) // If case exceeds 9
    {
      showType = 0;     // reset to case 0
    }
    delay(20);          // debounce delay
  }
  lastReading = reading;   // Update current state
  if (millis() - lastUpdate > patternInterval)
  {
    startShow(showType);
  }  

}  

void startShow(int showPattern)
{
  switch (showPattern)
  {
    case 0: ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE);
            break;
    case 1: ws2812fx.setMode(FX_MODE_THEATER_CHASE_RAINBOW);
            break;
    case 2: ws2812fx.setMode(FX_MODE_MERRY_CHRISTMAS);
            break;
    case 3: ws2812fx.setMode(FX_MODE_CHASE_RANDOM);
            break;
    case 4: ws2812fx.setMode(FX_MODE_FIREWORKS);
            break;
    case 5: ws2812fx.setMode(FX_MODE_FLASH_SPARKLE);
            break;
    case 6: ws2812fx.setMode(FX_MODE_SCAN);
            break;
    case 7: ws2812fx.setMode(FX_MODE_MULTI_DYNAMIC);
            break;
    case 8: ws2812fx.setMode(FX_MODE_CHASE_BLACKOUT);
            break;
    case 9: ws2812fx.setMode(FX_MODE_COMET);
            break;
  }
}

What I remember trying so far:

  1. Having switch/case in loop{} = no change
  2. Not using millis() "if" statement = no change
  3. Adding anything else to case statements = any addition causes "cannot compile" message
  4. Using showType variable in setup = no change
  5. Adding default mode in setup = went straight to case 0

Can I use switch/case with WS2812FX?

Yes.

I would have thought that your patternInterval time is way way too small for the patterns to be seen, this needs to be something like at least a few seconds.

You really should have posted a link to that Github, and a clickable one at that.

Grumpy_Mike:
I would have thought that your patternInterval time is way way too small for the patterns to be seen, this needs to be something like at least a few seconds.

Indeed. Changed it to 2000, but now the pattern restarts after the patternInterval lapses (regardless if it's 2000, 3000, or 5000). I wanted it to run through the entire pattern before it restarted.

It also won't move to the next pattern when the button is pressed until the patternInterval lapses. It does store the button press(es) while the pattern is running. If I press the button twice, it will advance two cases after the patternInterval.

I moved the lastUpdate=millis() from the loop to the individual cases. For example:

    case 0: ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE);
            break;

became

    case 0: ws2812fx.setMode(FX_MODE_RAINBOW_CYCLE);
            lastUpdate = millis();
            break;

When I do this for all 10 cases, I get the following compilation error message. If I comment out a case or leave the lastUpdate... part out, then it compiles without an error.

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)"

C:\Users\surve\Documents\Arduino\SketchBook\libraries\WS2812FX\src\WS2812FX.cpp: In member function 'setPixelColor':

C:\Users\surve\Documents\Arduino\SketchBook\libraries\WS2812FX\src\WS2812FX.cpp:119:1: internal compiler error: Segmentation fault

 }

 ^
lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.19.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Pro or Pro Mini.

Changed it to 2000, but now the pattern restarts after the patternInterval lapses (regardless if it's 2000, 3000, or 5000).

Sounds reasonable enough.

I wanted it to run through the entire pattern before it restarted.

I don’t think the library is written that way. There seems to be no way to get an indication of when a pattern has finished a cycle. There is a isCycle() function, you might try printing that out to see if it returns anything useful.

It does store the button press(es) while the pattern is running.

No all it does is advance the pattern number twice it doesn’t store the button presses. You could try to add

lastUpdate = patternInterval+1;

When you have detected a button press and incremented your pattern number.

We need to see the code that doesn’t compile before we can comment on that.