Need guidence with Neopixel ring & state changes with buttons

Hello I’m having some trouble with my program, I’m not very experienced with programming but I wanted to learn and achieve something for my project. I was looking at sample programs like the button cycle program from the neopixel library. What I am trying to attempt is when I press a button the pixel ring lights up red and colour wipes continuously so the leds are spinning around. then when that same button is pressed again I want it to turn off. I did have that part working, but once I started to add to the program I seem to of broke it. Reason why I want to use state changes is because I will be using multiple buttons with my project to make the pixel ring light different colours. I know there is a lot probably wrong with this, but I had a real good go at this before asking for a little help. If someone could tell me where I have gone wrong or even guide me that would be great. Thanks.

#include <Adafruit_NeoPixel.h>
        #ifdef __AVR__
        #include <avr/power.h>
        #endif
        
        #define PIXEL_PIN 11
        #define PIXEL_COUNT 12
        #define BUTTON_PIN   5
        
        // Parameter 1 = number of pixels in strip
        // Parameter 2 = Arduino pin number (most are valid)
        // Parameter 3 = pixel type flags, add together as needed:
        //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
        //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
        //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
        //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
        //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
        Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
        
        // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
        // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
        // and minimize distance between Arduino and first pixel.  Avoid connecting
        // on a live circuit...if you must, connect GND first.
        bool oldState = LOW;
        
        void setup() {
          pinMode(BUTTON_PIN, INPUT_PULLUP);
          strip.begin();
          strip.show(); // Initialize all pixels to 'off'
        }
        void loop() {
          // Get current button state.
          bool Record = digitalRead(BUTTON_PIN);
         // Check if state changed from high to low (button press).
          if (Record == HIGH && oldState == LOW) {
            // Short delay to debounce button
            delay(20);
            // Check if button is still low after debounce.
            Record = digitalRead(BUTTON_PIN);
          if (Record == HIGH) {
            colorWipe(strip.Color(255, 0, 0), 50); // Red
          } if (oldState == LOW); {
           colorWipe(strip.Color(0, 0, 0), 50); // Blank/off
          }
        }
        }
        // Fill the dots one after the other with a color
        void colorWipe(uint32_t c, uint8_t wait) {
          for (uint16_t i = 0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, c);
            strip.show();
            delay(wait);
          }
        }

You are not changing the value of oldState in your program

Okay, think I understand you I have just edited my program but its not fully right. Thank you for your reply

void loop() {
          // Get current button state.
          bool Record = digitalRead(BUTTON_PIN);
         // Check if state changed from high to low (button press).
          if (Record == HIGH && oldState == LOW) {
            // Short delay to debounce button
            delay(20);
            // Check if button is still low after debounce.
            Record = digitalRead(BUTTON_PIN);
          if (Record == HIGH) {
            colorWipe(strip.Color(255, 0, 0), 50); // Red
          } if (oldState == LOW); {
           colorWipe(strip.Color(0, 0, 0), 50); // Blank/off
          }
          if (oldState == HIGH); {
           colorWipe(strip.Color(255, 0, 0), 50); // Red
          }if (Record == LOW); {
           colorWipe(strip.Color(0, 0, 0), 50); // Blank/off
          }

The state change detection works by comparing the current state with the old state and taking action if they are different, ie the state has changed. To do this you need to know what the state was the last time you checked, hence the oldState variable. Before reading the current state save the previous state to oldState.

Review the StateChangeDetection example to see how it is done.

I've read the example over and over again, also looked at other examples. I just can't see where I'm going wrong. I might be being blind.

jovid196168: I've read the example over and over again, also looked at other examples. I just can't see where I'm going wrong. I might be being blind.

From the StateChangeDetection example

    // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;

Where is the equivalent in your program ?

I haven’t included that in my program, I was looking in the buttoncycler example. I attempted it again, but now I can’t get it to work. I’m guessing that’s because my lows and highs are all over the place. I have to set them the opposite because I’m using sustain pedals because of the polarity. I;m really sorry to be a pain if I am annoying you. I came up with this but it doesn’t work

#include <Adafruit_NeoPixel.h>
        #ifdef __AVR__
        #include <avr/power.h>
        #endif
        
        #define PIXEL_PIN 11
        #define PIXEL_COUNT 12
        #define BUTTON_PIN   5
        
        // Parameter 1 = number of pixels in strip
        // Parameter 2 = Arduino pin number (most are valid)
        // Parameter 3 = pixel type flags, add together as needed:
        //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
        //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
        //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
        //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
        //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
        Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
        
        // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
        // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
        // and minimize distance between Arduino and first pixel.  Avoid connecting
        // on a live circuit...if you must, connect GND first.
        bool oldState = HIGH;
        
        void setup() {
          pinMode(BUTTON_PIN, INPUT_PULLUP);
          strip.begin();
          strip.show(); // Initialize all pixels to 'off'
        }
void loop() {
  bool newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if (newState == HIGH && oldState == LOW) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW && oldState == HIGH) {
            colorWipe(strip.Color(255, 0, 0), 50); // Red
          }
      {if (oldState == HIGH); {
           colorWipe(strip.Color(0, 0, 0), 50); // Blank/off
          }
  }  
        }
        }
        // Fill the dots one after the other with a color
        void colorWipe(uint32_t c, uint8_t wait) {
          for (uint16_t i = 0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, c);
            strip.show();
            delay(wait);
          }
        }

I was looking in the buttoncycler example.

From the buttoncycler example

  // Set the last button state to the old state.
  oldState = newState;

Hello, I have made progress with my program, not sure if I have got it right or not? but it works when I press the pedal once it turns the neo pixel ring on and when I click it again it turns off. The one last thing that I want to add is for the lights to keep spinning around the wheel whilst it is on. I thought that it would do it with what is in the program but I am probably missing something. Any ideas? thank you

#include <Adafruit_NeoPixel.h>
        #ifdef __AVR__
        #include <avr/power.h>
        #endif
        
        #define PIXEL_PIN 11
        #define PIXEL_COUNT 12
        #define BUTTON_PIN   5
        
        // Parameter 1 = number of pixels in strip
        // Parameter 2 = Arduino pin number (most are valid)
        // Parameter 3 = pixel type flags, add together as needed:
        //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
        //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
        //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
        //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
        //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
        Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
        
        // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
        // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
        // and minimize distance between Arduino and first pixel.  Avoid connecting
        // on a live circuit...if you must, connect GND first.
        bool oldState = HIGH;
        int showType = 0;
        
        void setup() {
          pinMode(BUTTON_PIN, INPUT_PULLUP);
          strip.begin();
          strip.show(); // Initialize all pixels to 'off'
        }
void loop() {
  bool newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
     showType++;
      if (showType > 1)
        showType=0;
      startShow(showType);
    }
  }

  // Set the last button state to the old state.
  oldState = newState;
}

void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
            break;
    case 1: colorWipe(strip.Color(255, 0, 0), 50);  // Red
            break;
  }
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}


// 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);
}

I don't understand how pressing the pedal a second time turns the ring off if it's not spinning in the first place.

You need to separate the pedal state from the on/off state. The on/off state gets changed by a pedal press and the lights spinning is governed by the on/off state.

My suggestion is to make a new variable to keep track of the on/off state initialized to false.

bool lightsOn = false;  // on/off switch

When you get a confirmed pedal press change the value of this variable to the opposite of what it is set to. Each time through loop() if the on/off switch is ON you can wipe red then black. If the switch is OFF the lights are left black.

    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      lightsOn = !lightsOn; // flip switch
    }

    if ( lightsOn )
    {
      startShow(1);   // wipe red
      startShow(0);   // wipe black
    }

The caveat is that when startShow() is called it does not return to loop() until a wipe is completed so you will not be able to detect a pedal press right away. Holding it down until the spinning is completed will probably work.

I have added this into my program, seems that the checking state or the debouncing of the button stopped the colour wipe. Now as the code is, the pixel ring does colorwipe repetitively as I wanted it to. But when I press the pedal the pixel ring leds don't go out. Why could this be? Thank you for your reply. Someone on Reddit recommended using the fastled library instead of adafruits.

I have added this into my program

Now, only you can see where/how. If you are having problems, and want help, post your code.

Sorry, what I meant was I added what was suggested. So my program now looks like this, but something isn’t right. The pixel ring comes on but won’t turn off when pedal is pressed again.

        #include <Adafruit_NeoPixel.h>
                #ifdef __AVR__
                #include <avr/power.h>
                #endif
                
                #define PIXEL_PIN 11
                #define PIXEL_COUNT 12
                #define BUTTON_PIN   5
                
                // Parameter 1 = number of pixels in strip
                // Parameter 2 = Arduino pin number (most are valid)
                // Parameter 3 = pixel type flags, add together as needed:
                //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
                //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
                //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
                //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
                //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
                Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
                
                // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
                // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
                // and minimize distance between Arduino and first pixel.  Avoid connecting
                // on a live circuit...if you must, connect GND first.
                bool oldState = HIGH;
                bool lightsOn = false;  // on/off switch
                int showType = 0;
                
                void setup() {
                  pinMode(BUTTON_PIN, INPUT_PULLUP);
                  strip.begin();
                  strip.show(); // Initialize all pixels to 'off'
                }
        void loop() {
          bool newState = digitalRead(BUTTON_PIN);

        


    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      lightsOn = !lightsOn; // flip switch
    }

    if ( lightsOn )
    {
      startShow(1);   // wipe red
      startShow(0);   // wipe black
    }

          // Set the last button state to the old state.
          oldState = newState;
        }
        
        void startShow(int i) {
          switch(i){
            case 0: colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
                    break;
            case 1: colorWipe(strip.Color(255, 0, 0), 50);  // Red
                    break;
          }
        }
        
        // Fill the dots one after the other with a color
        void colorWipe(uint32_t c, uint8_t wait) {
          for(uint16_t i=0; i<strip.numPixels(); i++) {
            strip.setPixelColor(i, c);
            strip.show();
            delay(wait);
          }
        }
        
        
        // 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);
        }
          bool newState = digitalRead(BUTTON_PIN);

       


    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);

How long between those readings? You've thrown away the first reading, so you have nothing to compare it to, so the comment is useless.

    if (newState == LOW) {
      lightsOn = !lightsOn; // flip switch
    }

Why are you only concerned with the switch BEING pressed?

          // Set the last button state to the old state.
          oldState = newState;

That was useless, since you never care about the change in state.

The pixel ring comes on but won't turn off when pedal is pressed again.

Explain this. The pixel ring doesn't "come on". One pixel at a time is turned on with the specified color (initially red), until they are all on. Then, one pixel at a time is turned on with the specified color (black, effectively turning the pixel off).

You are ignoring the switch for the entire time this takes to happen, 1.2 seconds or more.

What actually happens when the sweep to red and then to off completes? Why do you think that pressing the switch again should turn the pixels off? They go off when the cycle completes, now. At least that's what the code says should happen.

I can see I have only payed attention to the switch being turned on only and I have tried to add for the switch to be turned off also. I don’t know if this is the correct way of doing this, I am trying my best here to succeed with this program. And I’m also trying to take on board with what you guys have said and where I am going wrong. At the moment with this program when the pedal is pressed the pixel ring lights up turning one led on, one after the other and stays lit. I press the pedal again and nothing happens. I know I’ve probably programmed it wrong but I thought I was getting somewhere. Think I’m getting HIGH’s and LOW’s mixed up to especially with the pedal polarity being the opposite. Thanks for your time.

        #include <Adafruit_NeoPixel.h>
                #ifdef __AVR__
                #include <avr/power.h>
                #endif
                
                #define PIXEL_PIN 11
                #define PIXEL_COUNT 12
                #define BUTTON_PIN   5
                
                // Parameter 1 = number of pixels in strip
                // Parameter 2 = Arduino pin number (most are valid)
                // Parameter 3 = pixel type flags, add together as needed:
                //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
                //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
                //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
                //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
                //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
                Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
                
                // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
                // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
                // and minimize distance between Arduino and first pixel.  Avoid connecting
                // on a live circuit...if you must, connect GND first.
                bool oldState = LOW;
                bool newState = HIGH;
                bool lightsOn = true;  // switch off
                bool lightsOff = false;  // switch on
                
                void setup() {
                  pinMode(BUTTON_PIN, INPUT_PULLUP);
                  strip.begin();
                  strip.show(); // Initialize all pixels to 'off'
                }
        void loop() {

          bool oldState = digitalRead(BUTTON_PIN);
  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    oldState = digitalRead(BUTTON_PIN);
    if (oldState == HIGH) {
      lightsOff = !lightsOff;} // switch off
      startShow(0);   // wipe black
  }
      
        bool newState = digitalRead(BUTTON_PIN);
        // Check if state changed from high to low (button press).
  if (newState == HIGH && oldState == LOW) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == HIGH)  {
      lightsOn =!lightsOn;} // switch on
      {startShow(1);   // wipe red
    }
  }
}      
        void startShow(int i) {
          switch(i){
            case 0: colorWipe(strip.Color(0, 0, 0), 50);    // Black/off
                    break;
            case 1: colorWipe(strip.Color(255, 0, 0), 50);  // Red
                    break;
          }
        }
        
        // Fill the dots one after the other with a color
        void colorWipe(uint32_t c, uint8_t wait) {
          for(uint16_t i=0; i<strip.numPixels(); i++) {
            strip.setPixelColor(i, c);
            strip.show();
            delay(wait);
          }
        }
        
        
        // 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);
        }

Below is some code that is tested working using an Arduino UNO, a momentary switch wired as active LOW and an 8 pixel Neo Pixel stick. When I upload the sketch it begins cycling red then black. The button toggles cycling on/off.

It borrows from the debounce tutorial code to turn the lights on or off.

There are two colors for each pixel: the on color and the off color. Each time through loop() if the lights are on and it is time to turn the next pixel on or off the pixel is set to the appropriate color. The color is determined by the number of times we have been through loop(). On even passes the pixels are turned on, on odd passes they are turned off.

If the lights are off all pixels are set to the off color.

This is demo code you can use to get ideas for how to structure your code. It works for me by YMMV and is presented so that you may have motivation on how to DIY.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIXEL_PIN 11
#define PIXEL_COUNT 8
#define BUTTON_PIN   5


// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

unsigned long colorOff = strip.Color(0, 0, 0);    // color when lights are off
unsigned long colorOn = strip.Color(255, 0, 0);   // color when lights are on
unsigned long spinTimer;                          // marks start of cycle
unsigned long spinInterval = 50UL;                // interval between light cycle
int pixIdx = 0;                                   // index into neo pixels

int lastButtonState = HIGH;   // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
int buttonState;             // the current reading from the input pin


int direction = 1;
int pixelIdx = 0;
unsigned long currentColor = colorOn;


// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.
bool oldState = LOW;
bool newState = HIGH;
bool lightsOn = true;  // switch off



void setup() {

  pinMode(BUTTON_PIN, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  spinTimer = millis(); // mark start of cycle


}
void loop() {

  // from debounce tutorial:  https://www.arduino.cc/en/Tutorial/Debounce

  // read the state of the switch into a local variable:
  int reading = digitalRead(BUTTON_PIN);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH), and you've waited long enough
  // since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // if we got a button push
      if (buttonState == LOW) {

        // toggle lights on
        lightsOn = !lightsOn;
      }
    }
  }

  // if we are cycling the lights
  if ( lightsOn )
  {
    // if it's time to cycle
    if ( (millis() - spinTimer) >= spinInterval )
    {
      // odd pass => turn pixel off, even pass => turn pixel on,
      strip.setPixelColor(pixIdx % PIXEL_COUNT, ((pixIdx / PIXEL_COUNT) % 2) ? colorOff : colorOn);
      strip.show();

      // increment index
      pixIdx++;
      
      // reset timer
      spinTimer = millis();

    } // if

  } else {

    // boom boom, out got the lights
    for (int i = 0; i < PIXEL_COUNT; i++)
    {

      strip.setPixelColor(i, colorOff);

    } // for

    strip.show();

    // reset timer
    spinTimer = millis();

    // reset index
    pixIdx = 0;


  } // if

  // save the reading. Next time through the loop, it'll be the lastButtonState:
  lastButtonState = reading;
}

Thank you for your reply. That code you sent has helped a lot, I just can't get the pixel ring to work as I want. At the moment it is lighting up as soon as the arduino is plugged in then turning off when the pedal is pressed. I need it to be the other way around for it to be off first then on.