0

Getting a "'colorWipe' was not declared in this scope"error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Getting a "'colorWipe' was not declared in this scope"error

by Ryan_S on Sat May 01, 2021 1:31 pm

I have recently been working on a project where when you press a button it toggles through different modes on an 8 LED Neopixel ring.

I have put together all the code (using the lines of code in the adafruit standtest_wheel example) and when I verify the code I recieve the following errors:


C:\Users\Ryan S******\Documents\Arduino\RGB_toggle_code\RGB_toggle_code.ino: In function 'void loop()':
RGB_toggle_code:53:1: error: 'colorWipe' was not declared in this scope
colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
^~~~~~~~~
RGB_toggle_code:59:33: error: expected ')' before ';' token
colorWipe(strip.Color(0, 0, 255); // Blue
^
RGB_toggle_code:65:33: error: expected ')' before ';' token
colorWipe(strip.Color(0, 255, 0); // Green
^
RGB_toggle_code:71:34: error: expected ')' before ';' token
colorWipe(strip.Color(255, 0, 0); // Red
^
RGB_toggle_code:76:40: error: a function-definition is not allowed here before '{' token
void theaterChaseRainbow(uint8_t wait) {
^
exit status 1
'colorWipe' was not declared in this scope


I have tried moving things around to see if that helps but that does not seem to have any effect, I have seen that there is a similar post (here: viewtopic.php?t=116724) but I am pretty sure that there is not any excess or missing brackets. I have attached the code below:

Thanks for any help


Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 12


Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);


const int buttonPin = 13;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int count_value =0;
int prestate =0;

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);


    strip.begin();
  strip.setBrightness(50);
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, then the buttonState is HIGH:
  if (buttonState == HIGH && prestate == 0) {
    count_value++;
 

    prestate = 1;
  }
  else if(buttonState == LOW) {
    prestate = 0;
  }

  if ( count_value = 0) {
  strip.show(); // Initialize all pixels to 'off'
   
  }

  if ( count_value = 1) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
   
  }
 
  if ( count_value = 2) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 0, 255); // Blue
   
  }

   if ( count_value = 3) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 255, 0); // Green
   
  }

   if ( count_value = 4) {
 strip.show(); // Initialize all pixels to 'off'
 colorWipe(strip.Color(255, 0, 0); // Red
   
  }

   if ( count_value = 5) {
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}
   
  }
 
    if ( count_value = 6) {
count_value = 0 ;
   
  }
}
Attachments
RGB_toggle_code.ino
(2.16 KiB) Not downloaded yet

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by adafruit_support_bill on Sat May 01, 2021 2:01 pm

You have not defined a colorWipe function anywhere in your code.

In the thread you referred to, he had defined a colorWipe function - but it was not recognized due to the imbalance of the brackets.

adafruit_support_bill
 
Posts: 81286
Joined: Sat Feb 07, 2009 10:11 am

Re: Getting a "'colorWipe' was not declared in this scope"er

by Ryan_S on Sat May 01, 2021 2:05 pm

Thanks for the reply,

I had a look through the Adafruit strandtest_wheel (code below) and I can't find a line of code that initialised the colorwipe function. It seems that when I take it out of the Void Loop() it works, however this would break the project as the whole point is to repeatedly check to see if the button has been pressed again?


Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6

// 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(60, 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.

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code

  strip.begin();
  strip.setBrightness(50);
  strip.show(); // Initialize all pixels to 'off'
    Serial.begin(9600); // open the serial port at 9600 bps:
}

void loop() {
  Serial.print (1);
  // Some example procedures showing how to display to the pixels:
  colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
}

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

void rainbow(uint8_t wait) {
    Serial.print (3);
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
    Serial.print (4);
  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));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
    Serial.print (5);
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
    Serial.print (6);
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}
// 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) {
    Serial.print (7);
  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);
}

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by adafruit_support_bill on Sat May 01, 2021 2:34 pm

I had a look through the Adafruit strandtest_wheel (code below) and I can't find a line of code that initialised the colorwipe function.

It is the first function that is defined after the loop:

Code: Select all | TOGGLE FULL SIZE
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
    Serial.print (2);
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

adafruit_support_bill
 
Posts: 81286
Joined: Sat Feb 07, 2009 10:11 am

Re: Getting a "'colorWipe' was not declared in this scope"er

by Ryan_S on Sat May 01, 2021 2:41 pm

Awesome!! thanks, that has solved that issue however I now get an....
expected ')' before ';' token
error here:
Code: Select all | TOGGLE FULL SIZE
colorWipe(strip.Color(0, 0, 255); // Blue
I'm not sure what it means by that error.

Thanks for helping me out

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by adafruit_support_bill on Sat May 01, 2021 2:43 pm

Your parentheses are unbalanced. You need another ')' to close out the parameter list in your call to colorWipe().

adafruit_support_bill
 
Posts: 81286
Joined: Sat Feb 07, 2009 10:11 am

Re: Getting a "'colorWipe' was not declared in this scope"er

by Ryan_S on Sat May 01, 2021 2:48 pm

I have just fixed the issue that was posted here before but now I have another error (ps sorry for taking up your time)

a function-definition is not allowed here before '{' token


here:

Code: Select all | TOGGLE FULL SIZE
uint32_t Wheel(byte WheelPos) {



I have put an updated version of my code below:

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 12


Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);


const int buttonPin = 13;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int count_value =0;
int prestate =0;

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

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);


    strip.begin();
  strip.setBrightness(50);
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, then the buttonState is HIGH:
  if (buttonState == HIGH && prestate == 0) {
    count_value++;
 

    prestate = 1;
  }
  else if(buttonState == LOW) {
    prestate = 0;
  }



  if ( count_value = 0) {
  strip.show(); // Initialize all pixels to 'off'
   
  }

  if ( count_value = 1) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
   
  }
 
  if ( count_value = 2) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 0, 255), 0); // Blue
   
  }

   if ( count_value = 3) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 255, 0), 0); // Green
   
  }

   if ( count_value = 4) {
 strip.show(); // Initialize all pixels to 'off'
 colorWipe(strip.Color(255, 0, 0), 0) ; // Red
   
  }

   if ( count_value = 5) {
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);
}
   
  }
 
    if ( count_value = 6) {
count_value = 0 ;
   
  }
}

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by adafruit_support_bill on Sat May 01, 2021 2:58 pm

You have defined the function "Wheel" in the middle of a conditional 'if' statement within you loop() function.

Code: Select all | TOGGLE FULL SIZE
   if ( count_value = 5) {
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);
}
   
  }


You can't define a function inside of another function. Move it to after the end of your loop() function.

adafruit_support_bill
 
Posts: 81286
Joined: Sat Feb 07, 2009 10:11 am

Re: Getting a "'colorWipe' was not declared in this scope"er

by Ryan_S on Sat May 01, 2021 3:05 pm

Ok, I see what you mean but I am not 100% sure how those lines of code work, I copied and pasted it off of the strandtest_wheel example which I know is pretty poor coding but this is the first time I've ever used neopixels.

Could you give me an example of where I could move that function and keep the effect (I believe that those lines of code do a rainbow wheel effect although I may be completely wrong)

Thanks

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by Ryan_S on Sat May 01, 2021 3:30 pm

I have changed the code to get rid of the swirl at the end but now all that happens is the rgb ring swirls in red and one of the neopixels just flashes white when the red swirl gets to it

Any ideas?

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by adafruit_support_bill on Sat May 01, 2021 3:37 pm

Without seeing the code it is impossible to diagnose anything.

adafruit_support_bill
 
Posts: 81286
Joined: Sat Feb 07, 2009 10:11 am

Re: Getting a "'colorWipe' was not declared in this scope"er

by Ryan_S on Sat May 01, 2021 3:39 pm

oh yes sorry here it is

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 12


Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);


const int buttonPin = 13;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int count_value =0;
int prestate =0;

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

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);


    strip.begin();
  strip.setBrightness(50);
  strip.show(); // Initialize all pixels to 'off'

 
}

void loop() {

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, then the buttonState is HIGH:
  if (buttonState == HIGH && prestate == 0) {
    count_value++;
 

    prestate = 1;
  }
  else if(buttonState == LOW) {
    prestate = 0;
  }



  if ( count_value = 0) {
  strip.show(); // Initialize all pixels to 'off'
  Serial.print (0);
   
  }

  if ( count_value = 1) {
colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  Serial.print (1) ;   
  }
 
  if ( count_value = 2) {
colorWipe(strip.Color(0, 0, 255), 0); // Blue
  Serial.print (2);   
  }

   if ( count_value = 3) {
colorWipe(strip.Color(0, 255, 0), 0); // Green
  Serial.print (3)  ; 
  }

   if ( count_value = 4) {
 colorWipe(strip.Color(255, 0, 0), 0) ; // Red
  Serial.print (4)    ;
  }

 
    if ( count_value = 5) {
count_value = 0 ;
  Serial.print (5) ;   
  }
}

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by adafruit_support_bill on Sat May 01, 2021 3:49 pm

Code: Select all | TOGGLE FULL SIZE
if ( count_value = 0) {

That statement assigns the value 0 to count_value. If you want to test for equality, you need to use the equality operator '=='.

Code: Select all | TOGGLE FULL SIZE
if ( count_value == 0) {


You have several instances of that same error in your code.

To learn about c++ operators, see this page: https://www.tutorialspoint.com/cplusplu ... rators.htm

That site is a good place to learn about the language in general: https://www.tutorialspoint.com/cplusplus/index.htm

adafruit_support_bill
 
Posts: 81286
Joined: Sat Feb 07, 2009 10:11 am

Re: Getting a "'colorWipe' was not declared in this scope"er

by Ryan_S on Sun May 02, 2021 6:32 am

Thanks, I didn't notice that.

I've now got one last error and that is

C:\Users\Ryan S******\Documents\Arduino\RGB_toggle_code\RGB_toggle_code.ino: In function 'void loop()':
RGB_toggle_code:88:31: error: a function-definition is not allowed here before '{' token
uint32_t Wheel(byte WheelPos) {


I recall that you mentioned before that this was because I
defined the function "Wheel" in the middle of a conditional 'if' statement within you loop() function.
, I am not sure how to fix this as that loop does a gradient clour loop (I think) and needs to be in the loop so that when it detects that
Code: Select all | TOGGLE FULL SIZE
( count_value == 5)
it changes the state so if it was out of the loop it would not constantly check for it.

Thanks,



(Code attached below)
Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 12


Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);


const int buttonPin = 13;     // the number of the pushbutton pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int count_value =0;
int prestate =0;

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

void setup() {
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);


    strip.begin();
  strip.setBrightness(50);
  strip.show(); // Initialize all pixels to 'off'

 
}

void loop() {

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, then the buttonState is HIGH:
  if (buttonState == HIGH && prestate == 0) {
    count_value++;
 

    prestate = 1;
  }
  else if(buttonState == LOW) {
    prestate = 0;
  }



  if ( count_value == 0) {
  strip.show(); // Initialize all pixels to 'off'
   
  }

  if ( count_value == 1) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
   
  }
 
  if ( count_value == 2) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 0, 255), 0); // Blue
   
  }

   if ( count_value == 3) {
strip.show(); // Initialize all pixels to 'off'
colorWipe(strip.Color(0, 255, 0), 0); // Green
   
  }

   if ( count_value == 4) {
 strip.show(); // Initialize all pixels to 'off'
 colorWipe(strip.Color(255, 0, 0), 0) ; // Red
   
  }

   if ( count_value == 5) {
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);
}
   
  }
 
    if ( count_value == 6) {
count_value = 0 ;
   
  }
}

Ryan_S
 
Posts: 27
Joined: Sat May 01, 2021 1:22 pm

Re: Getting a "'colorWipe' was not declared in this scope"er

by adafruit_support_bill on Sun May 02, 2021 6:50 am

I am not sure how to fix this as that loop does a gradient clour loop (I think) and needs to be in the loop so that when it detects that

You cannot define a function within another function. Move the function definition outside of your loop() function.

it changes the state so if it was out of the loop it would not constantly check for it.

It is a function, so you can call it from inside the loop(). Just like you do with colorWipe().

adafruit_support_bill
 
Posts: 81286
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.