HELP!- Animation cancelling

Hey Guys,
I am trying to do a nice under table lighting for my pc rig and I am using digital leds to accomplish that. In the code that I wrote using the adafruit library I am able to click a button and switch though static color presets, but when I try to do on the the rainbow animations it won’t let me go to the next “animation”/preset(which is supposed to be black). I was wondering if u guys could help me with that.
P.S. I tried to loop the rainbow animation

Here’s my code:

#include <Adafruit_NeoPixel.h>

#define BUTTON_PIN   2
#define PIXEL_PIN    6

#define PIXEL_COUNT 27
#define BLACK 0,0,0
#define RED 255,0,0
#define GREEN 0,255,0
#define BLUE 0,0,255
#define YELLOW 255,255,0
#define PURPLE 255,0,255

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldState = HIGH;
int showType = 0;
unsigned long animationUpdateTimestamp;
unsigned int animationUpdateInterval;
byte animationStep;

void setup() {

void loop() {
  bool newState = digitalRead(BUTTON_PIN);

  if (newState == LOW && oldState == HIGH) {
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      if (showType > 4)
        showType = 0;
  oldState = newState;

  //update animation
  if (millis() - animationUpdateTimestamp >= animationUpdateInterval) {  //it's time to update the animation
    animationUpdateTimestamp += animationUpdateInterval; //update timestamp
    switch (showType) {
      case 4:
        switch (animationStep) {  
               case 0:
            animationStep = 0;

void startShow(int i) {
  switch (i) {
    case 0:
      strip.setPixelColor(0, BLACK);
      strip.setPixelColor(1, BLACK);
      strip.setPixelColor(2, BLACK);
      strip.setPixelColor(3, BLACK);
      strip.setPixelColor(4, BLACK);
      strip.setPixelColor(5, BLACK);
      strip.setPixelColor(6, BLACK);
      strip.setPixelColor(6, BLACK);
      strip.setPixelColor(7, BLACK);
      strip.setPixelColor(8, BLACK);
      strip.setPixelColor(9, BLACK);
      strip.setPixelColor(10, BLACK);
      strip.setPixelColor(12, BLACK);
      strip.setPixelColor(13, BLACK);
      strip.setPixelColor(14, BLACK);
      strip.setPixelColor(16, BLACK);
      strip.setPixelColor(17, BLACK);
      strip.setPixelColor(18, BLACK);
      strip.setPixelColor(19, BLACK);
      strip.setPixelColor(20, BLACK);
      strip.setPixelColor(21, BLACK);
      strip.setPixelColor(22, BLACK);
      strip.setPixelColor(24, BLACK);
      strip.setPixelColor(25, BLACK);
      strip.setPixelColor(26, BLACK);;// Black/off
    case 1:
      strip.setPixelColor(0, RED);
      strip.setPixelColor(1, RED);
      strip.setPixelColor(2, RED);
      strip.setPixelColor(3, RED);
      strip.setPixelColor(4, RED);
      strip.setPixelColor(5, RED);
      strip.setPixelColor(6, RED);
      strip.setPixelColor(7, RED);
      strip.setPixelColor(8, RED);
      strip.setPixelColor(9, RED);
      strip.setPixelColor(10, RED);
      strip.setPixelColor(12, RED);
      strip.setPixelColor(13, RED);
      strip.setPixelColor(14, RED);
      strip.setPixelColor(16, RED);
      strip.setPixelColor(17, RED);
      strip.setPixelColor(18, BLUE);
      strip.setPixelColor(19, BLUE);
      strip.setPixelColor(20, BLUE);
      strip.setPixelColor(21, BLUE);
      strip.setPixelColor(22, RED);
      strip.setPixelColor(24, RED);
      strip.setPixelColor(25, RED);
      strip.setPixelColor(26, RED);;// Red/Blue
    case 2:
      strip.setPixelColor(0, GREEN);
      strip.setPixelColor(1, GREEN);
      strip.setPixelColor(2, GREEN);
      strip.setPixelColor(3, GREEN);
      strip.setPixelColor(4, GREEN);
      strip.setPixelColor(5, GREEN);
      strip.setPixelColor(6, GREEN);
      strip.setPixelColor(6, GREEN);
      strip.setPixelColor(7, GREEN);
      strip.setPixelColor(8, GREEN);
      strip.setPixelColor(9, GREEN);
      strip.setPixelColor(10, GREEN);
      strip.setPixelColor(12, GREEN);
      strip.setPixelColor(13, GREEN);
      strip.setPixelColor(14, GREEN);
      strip.setPixelColor(16, GREEN);
      strip.setPixelColor(17, GREEN);
      strip.setPixelColor(18, YELLOW);
      strip.setPixelColor(19, YELLOW);
      strip.setPixelColor(20, YELLOW);
      strip.setPixelColor(21, YELLOW);
      strip.setPixelColor(22, GREEN);
      strip.setPixelColor(24, GREEN);
      strip.setPixelColor(25, GREEN);
      strip.setPixelColor(26, GREEN);;// Green/Yellow
    case 3:
      strip.setPixelColor(0, BLUE);
      strip.setPixelColor(1, BLUE);
      strip.setPixelColor(2, BLUE);
      strip.setPixelColor(3, BLUE);
      strip.setPixelColor(4, BLUE);
      strip.setPixelColor(5, BLUE);
      strip.setPixelColor(6, BLUE);
      strip.setPixelColor(6, BLUE);
      strip.setPixelColor(7, BLUE);
      strip.setPixelColor(8, BLUE);
      strip.setPixelColor(9, BLUE);
      strip.setPixelColor(10, BLUE);
      strip.setPixelColor(12, BLUE);
      strip.setPixelColor(13, BLUE);
      strip.setPixelColor(14, BLUE);
      strip.setPixelColor(16, BLUE);
      strip.setPixelColor(17, BLUE);
      strip.setPixelColor(18, PURPLE);
      strip.setPixelColor(19, PURPLE);
      strip.setPixelColor(20, PURPLE);
      strip.setPixelColor(21, PURPLE);
      strip.setPixelColor(22, BLUE);
      strip.setPixelColor(24, BLUE);
      strip.setPixelColor(25, BLUE);
      strip.setPixelColor(26, BLUE);;// Blue/Purple
    case 4:
      animationUpdateInterval = 1000;
      animationStep = 0;
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);

Get rid of all the calls to delay()

You need to use Ctrl-A and Ctrl-X (or Cmd-A and Cmd-X on a Mac), and delete all that code.

Start over, using a state machine and millis() to determine when to make the next change. NO DELAY()S ALLOWED AND NO FOR LOOPS.

It looks like you combined code written to work with buttons with code written to work with a timer. Try changing the last case in your switch statement in startShow() to:

  case 4:

and see if that helps. If so, you can remove all code under the "update animation" comment in loop().

You need to use Ctrl-A and Ctrl-X (or Cmd-A and Cmd-X on a Mac), and delete all that code.

Start over, using a state machine and millis() to determine when to make the next change. NO DELAY()S ALLOWED AND NO FOR LOOPS.

I dont know how to code. LOL. I just put random examples together to see if they did what I wanted it to do. LOL

Well then LOL maybe it's time LOL to LOL learn or to LOL start paying people to LOL write LOL code for LOL you. There's only LOL so far LOL you can LOL go with LOL hack and paste coding.