Neopixel FASTled: run through examples with button

Hello,

I'm trying to run through the FASTled library examples with the press of a momentary button. So, press a button and the rainbow example will run, press it again and another example will run. I've managed to do the same thing with the Adafruit Lib but when trying to do a similar thing with the Fastled lib, I keep getting an error and I can't figure out why.

I removed the Adafruit lib to see if there was a clash but nope, same error.

Any ideas, please.

//#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <ESP8266WiFi.h>



#include "FastLED.h"

//#include "Button.h"                                           // Button library. Includes press, long press, double press detection.
//#include "JC_Button.h" //this worked prior


//from toher code
#define BUTTON_PIN   0
//#define PIN 2
//#define NUMPIXELS 8



#define PIN   2  //DATA_PIN

//#define CLK_PIN   11

#define LED_TYPE    WS2812

#define COLOR_ORDER GRB

#define NUMPIXELS    8   //NUM_LEDS

CRGB leds[NUMPIXELS];     //NUM_LEDS

boolean oldState = HIGH;
int     mode     = 0;    // Currently-active animation mode, 0-9

#define FRAMES_PER_SECOND  120



uint8_t max_bright = 64;



void setup() {

  Serial.begin(57600);

  delay(3000); // 3 second delay for recovery
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  

  FastLED.addLeds<LED_TYPE,PIN,COLOR_ORDER>(leds, NUMPIXELS).setCorrection(TypicalLEDStrip);

//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);



  // set master brightness control

  FastLED.setBrightness(max_bright);

}





// List of patterns to cycle through.  Each is defined as a separate function below.

typedef void (*SimplePatternList[])();

SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, juggle, bpm };  //deleted sinelon



uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current

uint8_t gHue = 0; // rotating "base color" used by many of the patterns

  

void loop()

{

  // Call the current pattern function once, updating the 'leds' array

  gPatterns[gCurrentPatternNumber]();



  // send the 'leds' array out to the actual LED strip

  FastLED.show();  

  // insert a delay to keep the framerate modest

  FastLED.delay(1000/FRAMES_PER_SECOND); 



  // do some periodic updates

  EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow

//  EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically



//    readbutton();                                               // Button press increases the ledMode up to last contiguous mode and then starts over at 0.

  // Get current button state.
  boolean 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) {      // Yes, still low
      if(++mode > 5) mode = 0; // Advance to next mode, wrap around after #8
      switch(mode) {           // Start the new animation...
        case 0:
          rainbow(50);    // Black/off
          break;
        case 1:
          rainbowWithGlitter(50);    // Red
          break;
        case 2:
          addGlitter(50);   // Green
          break;
        case 3:
          confetti(50);    // Blue
          break;
        case 4:
          bpm(50);    // White 
          break;
        case 5:
          juggle(50);       // Purple 
          break;

      }
    }
  }

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




}



#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))



//void nextPattern()

//{

  // add one to the current pattern number, and wrap around at the end

//  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);

//}



void rainbow() 

{

  // FastLED's built-in rainbow generator

  fill_rainbow( leds, NUMPIXELS, gHue, 7);

}



void rainbowWithGlitter() 

{

  // built-in FastLED rainbow, plus some random sparkly glitter

  rainbow();

  addGlitter(80);

}



void addGlitter( fract8 chanceOfGlitter) 

{

  if( random8() < chanceOfGlitter) {

    leds[ random16(NUMPIXELS) ] += CRGB::White;

  }

}



void confetti() 

{

  // random colored speckles that blink in and fade smoothly

  fadeToBlackBy( leds, NUMPIXELS, 10);

  int pos = random16(NUMPIXELS);

  leds[pos] += CHSV( gHue + random8(64), 200, 255);

}



//void sinelon()

//{

  // a colored dot sweeping back and forth, with fading trails

//  fadeToBlackBy( leds, NUM_LEDS, 20);

//  int pos = beatsin16(13,0,NUM_LEDS);

//  leds[pos] += CHSV( gHue, 255, 192);

//}



void bpm()

{

  // colored stripes pulsing at a defined Beats-Per-Minute (BPM)

  uint8_t BeatsPerMinute = 62;

  CRGBPalette16 palette = PartyColors_p;

  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);

  for( int i = 0; i < NUMPIXELS; i++) { //9948

    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));

  }

}



void juggle() {

  // eight colored dots, weaving in and out of sync with each other

  fadeToBlackBy( leds, NUMPIXELS, 20);

  byte dothue = 0;

  for( int i = 0; i < 8; i++) {

    leds[beatsin16(i+7,0,NUMPIXELS-1)] |= CHSV(dothue, 200, 255);

    dothue += 32;

  }

}





//void readbutton() {                                           // Read the button and increase the mode

//  myBtn.read();

//  if(myBtn.wasReleased()) {

//    nextPattern();


//  }

//} // readbutton()

I'll post the error next, as there is no room

The error


[code]Arduino: 1.8.8 (Windows 10), Board: "LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 921600"

C:\Users\MAGUIRES\Documents\Arduino\libraries\FastLED-master/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.003

 #    pragma message "FastLED version 3.003.003"

                     ^

In file included from C:\Users\MAGUIRES\Documents\Arduino\libraries\FastLED-master/FastLED.h:65:0,

                 from C:\Users\MAGUIRES\OneDrive\Elegoo\Projects\Blynk\StarProjector\ledbuttontest\ledandbuttonintegration\ledandbuttonintegration\ledandbuttonintegration.ino:7:

C:\Users\MAGUIRES\Documents\Arduino\libraries\FastLED-master/fastspi.h:130:23: note: #pragma message: No hardware SPI pins defined.  All SPI access will default to bitbanged output

 #      pragma message "No hardware SPI pins defined.  All SPI access will default to bitbanged output"

                       ^

ledandbuttonintegration:71:32: error: 'rainbow' was not declared in this scope

 SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, juggle, bpm };  //deleted sinelon

                                ^

ledandbuttonintegration:71:41: error: 'rainbowWithGlitter' was not declared in this scope

 SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, juggle, bpm };  //deleted sinelon

                                         ^

ledandbuttonintegration:71:61: error: 'confetti' was not declared in this scope

 SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, juggle, bpm };  //deleted sinelon

                                                             ^

ledandbuttonintegration:71:71: error: 'juggle' was not declared in this scope

 SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, juggle, bpm };  //deleted sinelon

                                                                       ^

ledandbuttonintegration:71:79: error: 'bpm' was not declared in this scope

 SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, juggle, bpm };  //deleted sinelon

                                                                               ^

C:\Users\MAGUIRES\OneDrive\Elegoo\Projects\Blynk\StarProjector\ledbuttontest\ledandbuttonintegration\ledandbuttonintegration\ledandbuttonintegration.ino: In function 'void loop()':

ledandbuttonintegration:124:21: error: 'rainbow' was not declared in this scope

           rainbow(50);    // Black/off

                     ^

ledandbuttonintegration:127:32: error: 'rainbowWithGlitter' was not declared in this scope

           rainbowWithGlitter(50);    // Red

                                ^

ledandbuttonintegration:130:24: error: 'addGlitter' was not declared in this scope

           addGlitter(50);   // Green

                        ^

ledandbuttonintegration:133:22: error: 'confetti' was not declared in this scope

           confetti(50);    // Blue

                      ^

ledandbuttonintegration:136:17: error: 'bpm' was not declared in this scope

           bpm(50);    // White 

                 ^

ledandbuttonintegration:139:20: error: 'juggle' was not declared in this scope

           juggle(50);       // Purple 

                    ^

C:\Users\MAGUIRES\OneDrive\Elegoo\Projects\Blynk\StarProjector\ledbuttontest\ledandbuttonintegration\ledandbuttonintegration\ledandbuttonintegration.ino: At global scope:

ledandbuttonintegration:153:1: error: expected declaration before '}' token

 }

 ^

Using library SPI at version 1.0 in folder: C:\Users\MAGUIRES\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\SPI 
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\MAGUIRES\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi 
Using library FastLED-master at version 3.3.3 in folder: C:\Users\MAGUIRES\Documents\Arduino\libraries\FastLED-master 
exit status 1
'rainbow' was not declared in this scope

[/code]

You have got your braces unbalanced. So the compiler is not seeing the function decelerations.

Put the cursor after an opening brace and the matching closing brace will have a box round it. You will find it doesn’t match where you think it should.

Okay, thank you. All working now.