Variable not declared in scope error

Hi everyone, I am attempting to use a button to cycle through neo pixel effects (from the Adafruit Neo-Pixel library example "simple") I copy and pasted the void functions for the effects as global variables but when I try to call them in case 1 it gives me the error "rainbow was not declared in this scope" (rainbow being a name of one of the effects)

Board: Arduino Uno
Any help is greatly appreciated!

#include <Adafruit_NeoPixel.h>

#define Button 3
#define Led_Data 4

#define LED_COUNT 120


int State = 0;
int Old = 0;
int Bstate = 0;

Adafruit_NeoPixel strip(LED_COUNT, Led_Data, NEO_GRB + NEO_KHZ800);

  void setup() {
    // put your setup code here, to run once:
    strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
    strip.show();            // Turn OFF all pixels ASAP
    strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
    pinMode(Button, INPUT);
    pinMode(Led_Data, OUTPUT);
  }

  void loop() {
    // put your main code here, to run repeatedly:
    Bstate = digitalRead(Button);
    if (Bstate == 1) {
      delay(100);
      Bstate = digitalRead(Button);
      if (Bstate == 0) {
        State = Old + 1;
      }
    }
    else {
      delay(100);
    }
    switch (State) {
      case 1:
        rainbow(10);
        Old = State;
        break;
    }
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
    for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the single-argument hue variant. The result
      // is passed through strip.gamma32() to provide 'truer' colors
      // before assigning to each pixel:
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    strip.show(); // Update strip with new contents
    delay(wait);  // Pause for a moment

Missing closing curly brackets for void loop(), void rainbow() and for (long firstPixelHue = 0 etc.

The number of opening and closing curly brackets must be balanced. Click Tools -> Auto Format in the IDE, so you can see if they are. Or just count them...

PS.: rainbow() is a function, not a variable. I changed the subject line.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.