Switch case executes first 2 cases, rest are useless

So I'm trying to make a LED strip with multiple programmed solid colors and effects with a switch case, but it doesn't execute a new line of code after the second case, and just does the first one again.

#include <FastLED.h>
#include <OneButton.h>


#define NUM_LEDS  30
#define LED_PIN   4
#define BTN_PIN   6   
long firstval = 0xff00ff;
CRGB rgbval(50,0,500);
CHSV hsvval(100,255,200);
uint8_t startpos = 0;
int endpos = NUM_LEDS-1;

uint8_t thishue = 0;
uint8_t deltahue = 15;


CRGB leds[NUM_LEDS];

uint8_t effectTeller = 0;

// Drukknop tussen pin 7 en GND

OneButton btn = OneButton(BTN_PIN, true, true);

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(50);
  Serial.begin(57600);

  btn.attachClick(volgEffect);
}

void loop() {
  
  switch (effectTeller) {
    case 0: 
fill_solid(leds,NUM_LEDS, CRGB::Red);

      break;
    case 1:
fill_solid(leds,NUM_LEDS, CRGB::Green);

      break;
      case 2:
fill_solid(leds,NUM_LEDS, CRGB:: Blue);
      break;
      case 3:

      break;
      case 4:

      break;
      case 5:


      break;
      case 6:

   break;
   
  }
  
  FastLED.show(); // Dit toont het gekozen effect op de strip
  btn.tick(); // Om ervoor te zorgen dat OneButton correct werkt, moeten we tick() aanroepen op elke knopinstantie binnen onze hoofdlus
}

void volgEffect() {
  effectTeller = (effectTeller + 1) % 2;           // Nummer achter % representeert het aantal effecten dat we gekozen hebben
}

//------- EFFECTEN LIJST -------//





//------- FRAMEWORK CODE -------//

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

How do I fix this?

This might be the problem.

What values do you expect for effectTeller, given the following:
effectTeller = (effectTeller + 1) % 2;

I totally forgot I made that line of code, I picked this project up from a while back so I forgot I did that. Thanks you two!

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