probably needs an startShow(showType); when you press the button
#include <WS2812FX.h>
#define LED_COUNT 182
#define LED_PIN 6
#define BTN_PIN 2 // the gpio number of the pushbutton
#define TIMER_MS 3000 // cycle effects every 2 seconds
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
const byte ALLoff = 0;
const byte HIGHLIGHT = 1;
const byte PATRIOTIC = 2;
const byte BREATH = 3;
const byte HOMERUN = 4;
unsigned long last_change = 0;
bool isCycling = false; // flag that enables cycling the effects
byte showType = 0;
void startShow(int i) {
Serial.println(i);
switch (i) {
case ALLoff:
ws2812fx.stop();
ws2812fx.removeActiveSegment(3);
ws2812fx.removeActiveSegment(2);
ws2812fx.removeActiveSegment(1);
ws2812fx.removeActiveSegment(0);
ws2812fx.start();
break;
case HIGHLIGHT:
ws2812fx.stop();
ws2812fx.addActiveSegment(0);
ws2812fx.start();
break;
case PATRIOTIC:
ws2812fx.stop();
ws2812fx.removeActiveSegment(0);
ws2812fx.addActiveSegment(1);
ws2812fx.start();
break;
case BREATH:
ws2812fx.stop();
ws2812fx.removeActiveSegment(1);
ws2812fx.addActiveSegment(2);
ws2812fx.start();
break;
case HOMERUN:
ws2812fx.stop();
ws2812fx.removeActiveSegment(2);
ws2812fx.addActiveSegment(0);
ws2812fx.addActiveSegment(3);
ws2812fx.start();
break;
}
}
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP); // config BTN_PIN as an input using internal pull-up resistor
Serial.begin(115200);
ws2812fx.init();
ws2812fx.setBrightness(100);
//from working sketch
ws2812fx.setIdleSegment(0, 0, 161, FX_MODE_BLINK, COLORS(WHITE, RED), 200, false); // segment 0 is leds 0 - 162 flash (homerun?)
ws2812fx.setIdleSegment(1, 0, 161, FX_MODE_TRICOLOR_CHASE, COLORS(WHITE, RED, BLUE), 15000, false); // segment 1 is leds 0 - 162 (patriotic)
ws2812fx.setIdleSegment(2, 0, 161, FX_MODE_BREATH, 0xFF0000, 5000, false); // segment 2 is leds 0 - 162 0xFF0000-RED (breathing)
ws2812fx.setIdleSegment(3, 162, 184, FX_MODE_COLOR_WIPE, RED, 100, false); // segment 3 is leds (red-circle)
ws2812fx.strip_off();
}
void loop() {
unsigned long now = millis();
if (!isCycling && digitalRead(BTN_PIN) == LOW) { // if button pressed, started cycling effects
last_change = now ;
showType = 0;
startShow(showType);
isCycling = true;
}
if (isCycling && (now - last_change > TIMER_MS)) { // go to next animation
if (++showType > 4) {
isCycling = false;
ws2812fx.strip_off();
ws2812fx.service();
}
else startShow(showType);
last_change = now;
}
if (isCycling) ws2812fx.service();
}
that's intended. You press, it starts the animations and then terminates. A new press will start again.