FastLED/NeoPixel examples that are non-blocking?

I have no idea how to separate to each RGB increment.

redIncrement = (redStartValue - redEndValue) / TotalSteps;
greenIncrement = (greenStartValue - greenEndValue) / TotalSteps;
blueIncrement = (blueStartValue - blueEndValue) / TotalSteps;

Am I on the right path? Using your help this is what I think I did. I defined 2 Colors and the steps. The floating variable next with your help. Finally telling what pixels and to start with Color 1 and then lighting the pixels. Is my thinking correct?

void fade(Color1, Color2, totalsteps) {
  TotalSteps = totalsteps;
  Color1 = (redStartValue, greenStartValue, blueStartValue);
  Color2 = (redEndValue, greenEndValue, blueEndValue);
 
  redIncrement = (redStartValue - redEndValue) / TotalSteps;
  greenIncrement = (greenStartValue - greenEndValue) / TotalSteps;
  blueIncrement = (blueStartValue - blueEndValue) / TotalSteps;

  for (int i = 0; i < strip.numPixels(); i++) {
  strip.setPixelColor(i, Color1);

  strip.show();
}
}

Is my thinking correct?

Not too sure because there is quite a lot missing. You need a state machine type of function that makes one step in the fade each time it is called. So you need to have either global variables or static variables that the function uses. Something like this, but it is not tested:-

void fade(int redStartValue, int redEndValue, int greenStartValue, int greenEndValueint, int blueStartValue, int blueEndValue, int totalsteps) {
static float redIncrement, greenIncrement, blueIncrement;
static float red, green, blue;
static int step = 0;

if (step == 0){ // first step is to initialise the initial colour and increments
  red = redStartValue;
  green = greenStartValue;
  blue = blueStartValue;

  redIncrement = (float)(redStartValue - redEndValue) / (float)totalSteps;
  greenIncrement = (float)(greenStartValue - greenEndValue) / (float)totalSteps;
  blueIncrement = (float)(blueStartValue - blueEndValue) / (float)totalSteps;
  step = 1; // next time the function is called start the fade
}
else { // all other steps make a new colour and display it
  // make new colour
  red += redIncrement;
  green +=  greenIncrement;
  blue += blueIncrement;
 
  // set up the pixel buffer
  for (int i = 0; i < strip.numPixels(); i++) {
  strip.setPixelColor(i, strip.Color((int)red,(int)green,(int)blue));
  }
 // now display it
  strip.show();
step += 1; // go on to next step
if(step > totalSteps) step = 0; // start again
 } 
}

That code works! There is no way I could have even come close to that. Feel free to just tell me to stop... but if I add another step, could I fade back to the original color? So at the end of the first else do something like

if(step > totalSteps) step = 2;

Then set up is if==2 and reverse the colors? Thanks again for your help!

If you want to fade back to the original colours then in place of this:-

if(step > totalSteps) step = 0; // start again

You could use this, again not tested:-

if(step > totalSteps) {
  redIncrement = -redIncrement;
  greenIncrement = -greenIncrement;
  blueIncrement = -blueIncrement;

step = 1; // don't calculate the increments again but start at first change
}

By simply making the increments the negitave of what they were, you should be able to fade back to the the original colour.

OK I have now tested this and made a few changes to make it work better and stop the flash at the fade switch around. This is the complete sketch for the state machine function with the fade function added.

// StrandTest from AdaFruit implemented as a state machine
// pattern change by push button
// By Mike Cook Jan 2016
// Fade function added Sept 2017

#define PINforControl   7 // pin connected to the small NeoPixels strip
#define NUMPIXELS1      256 // number of LEDs on strip

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS1, PINforControl, NEO_GRB + NEO_KHZ800);

unsigned long patternInterval = 20 ; // time between steps in the pattern
unsigned long lastUpdate = 0 ; // for millis() when last update occoured
unsigned long intervals [] = { 20, 20, 50, 100, 30 } ; // speed for each pattern - add here when adding more cases 
int fadeStep = 0; // stste variable for fade function
int numberOfCases = 4; // how many case statements or patterns you have
const byte button = 2; // pin to connect button switch to between pin and ground

void setup() {
  strip.begin(); // This initializes the NeoPixel library.
  wipe(); // wipes the LED buffers
  pinMode(button, INPUT_PULLUP); // change pattern button
}

void loop() {
  static int pattern = 4, lastReading; // start with the fade function
  int reading = digitalRead(button);
  if(lastReading == HIGH && reading == LOW){
    pattern++ ; // change pattern number
    fadeStep = 0; // reset the fade state variable
    if(pattern > numberOfCases) pattern = 0; // wrap round if too big
    patternInterval = intervals[pattern]; // set speed for this pattern
    wipe(); // clear out the buffer
    delay(50); // debounce delay
  }
  lastReading = reading; // save for next time

if(millis() - lastUpdate > patternInterval) updatePattern(pattern);
}

void  updatePattern(int pat){ // call the pattern currently being created
  switch(pat) {
    case 0:
        rainbow();
        break;
    case 1:
        rainbowCycle();
        break;
    case 2:
        theaterChaseRainbow();
        break;
    case 3:
         colorWipe(strip.Color(255, 0, 0)); // red
         break; 
         
    case 4:
         fade(0,255, 0,64, 0,0, 400); // fade from black to oraange and back
         break;                  
  } 
}

void fade(int redStartValue, int redEndValue, int greenStartValue, int greenEndValue, int blueStartValue, int blueEndValue, int totalSteps) {
static float redIncrement, greenIncrement, blueIncrement;
static float red, green, blue;
static boolean fadeUp = false;

if (fadeStep == 0){ // first step is to initialise the initial colour and increments
  red = redStartValue;
  green = greenStartValue;
  blue = blueStartValue;
  fadeUp = false;

  redIncrement = (float)(redEndValue - redStartValue) / (float)totalSteps;
  greenIncrement = (float)(greenEndValue - greenStartValue) / (float)totalSteps;
  blueIncrement = (float)(blueEndValue - blueStartValue) / (float)totalSteps;
  fadeStep = 1; // next time the function is called start the fade
}
else { // all other steps make a new colour and display it
  // make new colour
  red += redIncrement;
  green +=  greenIncrement;
  blue += blueIncrement;
 
  // set up the pixel buffer
  for (int i = 0; i < strip.numPixels(); i++) {
  strip.setPixelColor(i, strip.Color((int)red,(int)green,(int)blue));
  }
 // now display it
  strip.show();
fadeStep += 1; // go on to next step
if(fadeStep >= totalSteps) { // finished fade
  if(fadeUp){ // finished fade up and back
     fadeStep = 0;
     return; // so next call recalabrates the increments 
  }
  // now fade back
  fadeUp = true;
  redIncrement = -redIncrement;
  greenIncrement = -greenIncrement;
  blueIncrement = -blueIncrement;
  fadeStep = 1; // don't calculate the increments again but start at first change
}
 }
}

void rainbow() { // modified from Adafruit example to make it a state machine
  static uint16_t j=0;
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
     j++;
  if(j >= 256) j=0;
  lastUpdate = millis(); // time for next change to the display
 
}
void rainbowCycle() { // modified from Adafruit example to make it a state machine
  static uint16_t j=0;
    for(int i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
  j++;
  if(j >= 256*5) j=0;
  lastUpdate = millis(); // time for next change to the display
}

void theaterChaseRainbow() { // modified from Adafruit example to make it a state machine
  static int j=0, q = 0;
  static boolean on = true;
     if(on){
            for (int i=0; i < strip.numPixels(); i=i+3) {
                strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
             }
     }
      else {
           for (int i=0; i < strip.numPixels(); i=i+3) {
               strip.setPixelColor(i+q, 0);        //turn every third pixel off
                 }
      }
     on = !on; // toggel pixelse on or off for next time
      strip.show(); // display
      q++; // update the q variable
      if(q >=3 ){ // if it overflows reset it and update the J variable
        q=0;
        j++;
        if(j >= 256) j = 0;
      }
  lastUpdate = millis(); // time for next change to the display   
}

void colorWipe(uint32_t c) { // modified from Adafruit example to make it a state machine
  static int i =0;
    strip.setPixelColor(i, c);
    strip.show();
  i++;
  if(i >= strip.numPixels()){
    i = 0;
    wipe(); // blank out strip
  }
  lastUpdate = millis(); // time for next change to the display
}


void wipe(){ // clear all LEDs
     for(int i=0;i<strip.numPixels();i++){
       strip.setPixelColor(i, strip.Color(0,0,0));
       }
}

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

Thanks Mike! That code works perfect! This has certainly been a learning experience. Thanks for all your help.

I would like to bring this thread back if I can. I had a similar question with a very different application. I too am a newb and the code poster on here helped me a lot. But I’m trying to implement it in my own code in two different ways but not sure how.

Here is what I have so far. You‚Äôll notice where I used ‚Äúnon-blocking‚ÄĚ code, but the LtBlink/RtBlink is what I‚Äôm having trouble with. (had to erase most of the PROGMEM data in the sketch to fit in the forum)

#include <Adafruit_NeoPixel.h>


#define PIN_A 23
#define PIN_B 22
#define PIN_C 25
#define PIN_D 24
#define LENGTH 41

int allStrips [] ={
  22, 23, 24, 25
};

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(LENGTH, PIN_A, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(LENGTH, PIN_B, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(LENGTH, PIN_C, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(LENGTH, PIN_D, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel stripAll = Adafruit_NeoPixel(LENGTH, allStrips, NEO_GRBW + NEO_KHZ800);

int const LtBlinkPin = A1;
int const RtBlinkPin = A2;
int const HeadLtPin = A3;

int LtBlinkValue;
int RtBlinkValue;
int HeadLtValue;
int frames = 41;
int fps = 82;

float HeadLtVolt = 0;
float LtBlinkVolt = 0;
float RtBlinkVolt = 0;

//This data array is a R, G, B values in sequence. The pixels from the first frame are first, followed by the next frame, etc..
//We're storing this in PROGMEM (see note below) to save space in RAM which is normally more constrained
const byte data[] PROGMEM = {255, 255, 0, 255, 214, 0, 255, 39, 39, 101, 101, 101, 157, 157, 157, 225, 225, 225, 253, 253, 212, 255, 255, 163, 255, 255, 0};

const byte data1[] PROGMEM = {0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

void setup() {

  pinMode(HeadLtPin, INPUT);
  pinMode(RtBlinkPin, INPUT);
  pinMode(LtBlinkPin, INPUT);


  strip1.begin();
  strip1.show();

  strip2.begin();
  strip2.show();

  strip3.begin();
  strip3.show();

  strip4.begin();
  strip4.show();

  wipe1();
  wipe2();
  wipe3();
  wipe4();
}

int currentFrame = 0;

void loop() {


  //left blinker reading
  LtBlinkValue = analogRead(LtBlinkPin);

  float LtV;

  LtV = LtBlinkValue / 4.092;
  LtBlinkVolt = (LtV / 10);

  //Right blinker reading
  RtBlinkValue = analogRead(RtBlinkPin);

  float RtV;

  RtV = LtBlinkValue / 4.092;
  RtBlinkVolt = (LtV / 10);


  //Headlight reading
  HeadLtValue = analogRead(HeadLtPin);

  float HeadV;

  HeadV = HeadLtValue / 4.092;
  HeadLtVolt = (HeadV / 10);

  if (HeadLtVolt >= 11) {

    colorWipe1(strip1.Color(0, 0, 0, 255), 50);
    colorWipe2(strip2.Color(0, 0, 0, 255), 50);
    colorWipe3(strip3.Color(0, 0, 0, 255), 50);
    colorWipe4(strip4.Color(0, 0, 0, 255), 50); // White RGBW

  } else if (HeadLtVolt <= 8) {

    colorWipe1(strip1.Color(0, 0, 0, 0), 0);
    colorWipe2(strip2.Color(0, 0, 0, 0), 0);
    colorWipe3(strip3.Color(0, 0, 0, 0), 0);
    colorWipe4(strip4.Color(0, 0, 0, 0), 0);
  }

  if (LtBlinkVolt >= 11) { //left blinker

    LtBlink();
    colorWipe3(strip3.Color(0, 255, 255, 255), 255);

  } else if (LtBlinkVolt <= 8 && HeadLtVolt >= 11) {

    colorWipe5(stripAll.Color(0, 255, 255, 255), 255);
  }
  
  
  if (RtBlinkVolt >= 11) { //right blinker

    RtBlink();
    colorWipe2(strip2.Color(0, 255, 255, 255), 255);
  } else if (RtBlinkVolt <= 8 && HeadLtVolt >= 11) {

    colorWipe1(strip1.Color(0, 255, 255, 255), 255);
    colorWipe2(strip2.Color(0, 255, 255, 255), 255);
    colorWipe3(strip3.Color(0, 255, 255, 255), 255);
    colorWipe4(strip4.Color(0, 255, 255, 255), 255);
   
    
  }

  if (LtBlink <= 12 && RtBlink <= 12) {
    
  RtBlink();
  LtBlink();
  }
  
void RtBlink() {
  for (uint16_t i = 0; i < strip1.numPixels(); i++) {
    int pixelIndex = i % LENGTH;
    int index = currentFrame * LENGTH * 3 + pixelIndex * 3;

    //Note: We're using pgm_read_byte_near to read bytes out of the data array stored in PROGMEM. These functions are not required for all configurations
    strip1.setPixelColor(i, pgm_read_byte_near(data + index), pgm_read_byte_near(data + index + 1), pgm_read_byte_near(data + index + 2));

  }
  strip1.show();

  currentFrame ++;
  if (currentFrame >= frames) currentFrame = 0;
  delay(1000 / fps);
}

void LtBlink() {
  for (uint16_t i = 0; i < strip4.numPixels(); i++) {
    int pixelIndex = i % LENGTH;
    int index = currentFrame * LENGTH * 3 + pixelIndex * 3;
    strip4.setPixelColor(i, pgm_read_byte_near(data1 + index), pgm_read_byte_near(data1 + index + 1), pgm_read_byte_near(data1 + index + 2));

  }
  strip4.show();

  currentFrame ++;
  if (currentFrame >= frames) currentFrame = 0;
  delay(1000 / fps);
}

// Fill the dots one after the other with a color one ring at a time
void colorWipe1(uint32_t color) {
  static uint8_t wait = 50;
  static unsigned long lastUpdate = 0;
  static uint16_t currentLed = 0;
 
  unsigned long now = millis();
  if (now > lastUpdate+delay) {
    strip1.setPixelColor(currentLed, color);
    strip1.show();   
    currentLed = currentLed>strip1.numPixels() ? 0 : currentLed+1;
    lastUpdate = now;
  }
}

void colorWipe2(uint32_t color) {
  static uint8_t wait = 50;
  static unsigned long lastUpdate = 0;
  static uint16_t currentLed = 0;
 
  unsigned long now = millis();
  if (now > lastUpdate+delay) {
    strip2.setPixelColor(currentLed, color);
    strip2.show();   
    currentLed = currentLed>strip2.numPixels() ? 0 : currentLed+1;
    lastUpdate = now;
  }
}

void colorWipe3(uint32_t color) {
  static uint8_t wait = 50;
  static unsigned long lastUpdate = 0;
  static uint16_t currentLed = 0;
 
  unsigned long now = millis();
  if (now > lastUpdate+delay) {
    strip3.setPixelColor(currentLed, color);
    strip3.show();   
    currentLed = currentLed>strip3.numPixels() ? 0 : currentLed+1;
    lastUpdate = now;
  }
}

void colorWipe4(uint32_t color) {
  static uint8_t wait = 50;
  static unsigned long lastUpdate = 0;
  static uint16_t currentLed = 0;
 
  unsigned long now = millis();
  if (now > lastUpdate+delay) {
    strip4.setPixelColor(currentLed, color);
    strip4.show();   
    currentLed = currentLed>strip4.numPixels() ? 0 : currentLed+1;
    lastUpdate = now;
  }
}

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
  // NeoPixel
  strip1.show();
  strip2.show();
  strip3.show();
  strip4.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
  // NeoPixel
  strip1.setPixelColor(Pixel, strip1.Color(red, green, blue));
  strip2.setPixelColor(Pixel, strip2.Color(red, green, blue));
  strip3.setPixelColor(Pixel, strip3.Color(red, green, blue));
  strip4.setPixelColor(Pixel, strip4.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 < LENGTH; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

I can't make any sense of this line:

Adafruit_NeoPixel stripAll = Adafruit_NeoPixel(LENGTH, allStrips, NEO_GRBW + NEO_KHZ800);

What did you intend that to mean?

Hi there Mike - amazing code and has helped me so much. I'm setting up a project for some children in my local special needs school.

We are trying to teach them how to press buttons and light up neopixels.

I was wondering if your code above "StrandTest from AdaFruit implemented as a state machine" can be amended so instead of having a single button to increment through each lighting effect, the lighting effects could be assigned to individual buttons - so would have four.

this could help my kids learn pattens ie when they press the rainbow button, they would get a rainbow effect, press a flashing button, they would get a flashing effect?

thank you so much in advance

Yes, that won't be a problem. In fact, easier than using a single button. With a button dedicated to each pattern, it won't be necessary to debounce the button(s).

Ohhhh fantastic. i apologise in advance for being very new to learning code. Would you know where i would look to learn how to do this Paul?

I'm not sure what i would omit or add it at this point. Thank you in advance if you could point me in the direction. Thank you Leon

apologise in advance for being very new to learning cod

No need we are here to help.

I'm not sure what i would omit or add it at this point.

In that code when a button is pressed a count is incremented, it is this count that determines what pattern is produced. Just remove the increment bit and look at each pin in turn and set that count to the value 0 to 3 depending on if it was the first, second, third or fourth button was pressed. I can’t remember the variable names at the moment I am on my iPad, but set all the button pins to INPUT_PULLUP and wire the buttons between input and ground, then simply do.

if (digitalRead(pin1) == LOW) count = 0;
if (digitalRead(pin2) == LOW) count = 1;
if (digitalRead(pin3) == LOW) count = 2;
if (digitalRead(pin4) == LOW) count = 3;

Hello there guys
I have declared in the additional buttons at the top of the script (below),
I’ve added them into the void setup part,
I‚Äôve added the If statements into the void loop and commented out the ‚Äėpattern++‚Äô part, but i think i should have done more. I‚Äôm getting an error saying:

‚Äėcount‚Äô was not declared in this scope

I have copied the code below - thank you Leon

///////////////////////////////////

#define PINforControl 5 // pin connected to the small NeoPixels strip
#define NUMPIXELS 16 // number of LEDs on second strip

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PINforControl, NEO_GRB + NEO_KHZ800);

unsigned long patternInterval = 20 ; // time between steps in the pattern
unsigned long lastUpdate = 0 ; // for millis() when last update occoured
unsigned long intervals [] = { 20, 5, 50, 100 } ; // speed for each pattern
const byte button_1 = 8; // pin to connect button switch to between pin and ground
const byte button_2 = 9; // pin to connect button switch to between pin and ground
const byte button_3 = 10; // pin to connect button switch to between pin and ground
const byte button_4 = 11; // pin to connect button switch to between pin and ground

void setup() {
 strip.begin(); // This initializes the NeoPixel library.
 //wipe(); // wipes the LED buffers
 pinMode(button_1, INPUT_PULLUP); // change pattern button
 pinMode(button_2, INPUT_PULLUP);
 pinMode(button_3, INPUT_PULLUP);
 pinMode(button_4, INPUT_PULLUP);
 strip.setBrightness(30);
}

void loop() {
 static int pattern = 0, lastReading;
 int reading = digitalRead(button_1);
 if(lastReading == HIGH && reading == LOW){
   //pattern++ ; // change pattern number
 if (digitalRead(button_1) == LOW) count = 0;
 if (digitalRead(button_2) == LOW) count = 1;
 if (digitalRead(button_3) == LOW) count = 2;
 if (digitalRead(button_4) == LOW) count = 3;
   if(pattern > 3) pattern = 0; // wrap round if too big
   patternInterval = intervals[pattern]; // set speed for this pattern
   wipe(); // clear out the buffer
   delay(50); // debounce delay
 }
 lastReading = reading; // save for next time

if(millis() - lastUpdate > patternInterval) updatePattern(pattern);
}

void  updatePattern(int pat){ // call the pattern currently being created
 switch(pat) {
   case 0:
       rainbow();
       break;
   case 1:
       rainbowCycle();
       break;
   case 2:
       theaterChaseRainbow();
       break;
   case 3:
        colorWipe(strip.Color(255, 0, 0)); // red
        break;  
 }  
}

void rainbow() { // modified from Adafruit example to make it a state machine
 static uint16_t j=0;
   for(int i=0; i<strip.numPixels(); i++) {
     strip.setPixelColor(i, Wheel((i+j) & 255));
   }
   strip.show();
    j++;
 if(j >= 256) j=0;
 lastUpdate = millis(); // time for next change to the display
 
}
void rainbowCycle() { // modified from Adafruit example to make it a state machine
 static uint16_t j=0;
   for(int i=0; i< strip.numPixels(); i++) {
     strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
   }
   strip.show();
 j++;
 if(j >= 256*5) j=0;
 lastUpdate = millis(); // time for next change to the display
}

void theaterChaseRainbow() { // modified from Adafruit example to make it a state machine
 static int j=0, q = 0;
 static boolean on = true;
 // for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
 //  for (int q=0; q < 3; q++) {
    if(on){
           for (int i=0; i < strip.numPixels(); i=i+3) {
               strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
            }
    }
     else {
          for (int i=0; i < strip.numPixels(); i=i+3) {
              strip.setPixelColor(i+q, 0);        //turn every third pixel off
                }
     }
    on = !on; // toggel pixelse on or off for next time
     strip.show(); // display
     q++; // update the q variable
     if(q >=3 ){ // if it overflows reset it and update the J variable
       q=0;
       j++;
       if(j >= 256) j = 0;
     }
 lastUpdate = millis(); // time for next change to the display    
}

void colorWipe(uint32_t c) { // modified from Adafruit example to make it a state machine
 static int i =0;
   strip.setPixelColor(i, c);
   strip.show();
 i++;
 if(i >= strip.numPixels()){
   i = 0;
   wipe(); // blank out strip
 }
 lastUpdate = millis(); // time for next change to the display
}


void wipe(){ // clear all LEDs
    for(int i=0;i<strip.numPixels();i++){
      strip.setPixelColor(i, strip.Color(0,0,0));
      }
}

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

Come on now please read this:-
How to use this forum
Because your post is breaking the rules about posting code. Please edit that last post, select just the code and then press the </> icon, top left. Then save and your code will be in a proper box just like mine.

I’m getting an error saying:

‚Äėcount‚Äô was not declared in this scope

That is because it wasn’t declared. Remember I said:-

I can’t remember the variable names at the moment I am on my iPad,

So you should have seen I didn‚Äôt use ‚Äúcount‚ÄĚ but ‚Äúpattern‚ÄĚ as the variable that defined the what animation to produce. The first step in learning how to code is learning how to read code.

So what level of understanding do you have because you have missed other stuff as well. That code was written as an example of what you had to do to make every button produce a different pattern. You have left in the code that detects the falling edge from the original switch and also the code that wraps round its value.
This means that even when you get the variable right the pattern will only change when you push button_1.

thank you Leon

Who is Leon?
EDIT Oh its you. Sorry I thought you were saying thanks ‚Äúto‚ÄĚ someone not ‚Äúthanks from‚ÄĚ.

Ahhh thank you, wasn't aware of the 'code' tab.

I'm new to arduino and loving learning the basics.

I was setting up a sensory room for children with special sensory needs.

Some of the equipment costs thousands of pounds due to the fact it's not mainstream.

I'd seen neopixels and arduino's over the years and they are very cheep - so i was making the lighting for our sensory room, where children can press a button and get the lights to do tricks.

A single button was no good as they have to pick either a button that is coloured blue to make the lights blue, a red button to make the lights red.

I guess i need to read up on 'if' statements then.

Thank you for your help and input

I do some work with disabled people who want to make music, we would normally have met today the last Monday in the month. We are Drake Music Labs North, the main group is in London.

So I am very sympathetic with what you are trying to do. But I am also keen on teaching you how to program. If you want to stick with it I can guide you through this. I think that when you acquire programming skills you can do a lot more in this field and you will get a double sense of achievement.

This is a good problem to tackle because it is not too hard, but if you want to I could just write the code for you.