Please note: Friday June 18 is a holiday celebrating Juneteenth, please allow extra time for your order to arrive and plan accordingly.
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.

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

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

Ok, I am not sure how that code works so what part would I need to move out of the loop?
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 Sun May 02, 2021 6:58 am

Ok thanks,

I am not sure where it defines the function as it seems like it acts a bit like an 'if' function, and secondly since I am not sure what function it defines I am not sure as to how to call it from inside the loop.

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 7:17 am

I am not sure where it defines the function

This is your function definition. It needs to be moved outside of the loop().

Code: Select all | TOGGLE FULL SIZE
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);
}


as it seems like it acts a bit like an 'if' function, and secondly since I am not sure what function it defines I am not sure as to how to call it from inside the loop.

The wheel function is not at all like an 'if' statement. You call the wheel function with a number between 0 and 255 and it returns a color from the color wheel.

If you do not understand what a function is, you should refer to this page: https://www.tutorialspoint.com/cplusplu ... ctions.htm

adafruit_support_bill
 
Posts: 81308
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 7:28 am

Ahhhhh I understand now, I am pretty sure I accidentally copied the wrong code across, I don't really need it anyways.

When I upload the code now (below) the ring does not turn on and when I push the button nothing happens, when I pull the jumper cables out of the breadboard and manually touch them together the LED ring repeats what happened before with the LED ring continually circling red.

edit: it now appears that the jumper cables to the button do not do anything and it does it without any input and there are no errors in the IDE

when I look at the serial monitor the monitor constantly repeats 1 then posts "222223333344445" then loads of zeroes, three ones and then just stops communicating through serial and starts swirling in red



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 Sun May 02, 2021 7:37 am

How do you have your button wired? Please post a photo showing all your wiring and connections.

adafruit_support_bill
 
Posts: 81308
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 7:48 am

There you go, I had to use the image of a strip because tinkercad doesn't have an eight pixel ring in its library.

here is the code for reference: I believe that the ring is RGB only now so I have changed the code slightly so now all that happens is the ring turns on white and stays that way


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(255, 255, 255), 50); // White RGBW
  Serial.print (1) ;   
  }
 
  if ( count_value == 2) {
colorWipe(strip.Color(0, 0, 255), 50); // Blue
  Serial.print (2);   
  }

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

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

 
    if ( count_value == 5) {
count_value = 0 ;
  Serial.print (5) ;   
  }
}
Attachments
Screenshot (291).png
Screenshot (291).png (129.67 KiB) Viewed 76 times

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 Sun May 02, 2021 8:12 am

I believe the issue may be the reading of the pin as when I remove the prestate value (not 100% neccesary) the arduino cycles through all the stages (0 to 1 to 2 to 3 to 4 to 5 and then to 0 again) without stopping so maybe it is constantly reading a high value?

Correction: when I keep the prestate value and serial print in the count_value it stays always stays at 1 which is very strange, it therefore must add one because it thinks it has a signal from the button and then not recieve any more data?
Last edited by Ryan_S on Sun May 02, 2021 8:17 am, edited 1 time in total.

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 8:15 am

Your switch input is floating, so the value is unpredictable when not pressed. You need a pulldown resistor on your switch.

https://learn.adafruit.com/circuit-play ... ing-inputs

adafruit_support_bill
 
Posts: 81308
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 8:36 am

That's done and my circuit now looks like the image below, when I power on the arduino the light goes off (as it should) however when I press the button nothing happens and the 'count_value' variable stays at zero constantly.

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;

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

void rainbow(uint8_t wait) {
  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) {
  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) {
  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) {
  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) {
  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);
}

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

Serial.print (count_value);

  if ( count_value == 0) {
colorWipe(strip.Color(0, 0, 0), 50); // White RGBW

   
  }

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

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

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

  }
   if ( count_value == 5) {
  rainbow(50);

  }
 
    if ( count_value == 6) {
count_value = 0 ;

  }
}
Attachments
Screenshot (292).png
Screenshot (292).png (144.05 KiB) Viewed 74 times

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 8:39 am

Your pulldown is not wired correctly. It should be between pin 13 and GND.

adafruit_support_bill
 
Posts: 81308
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 8:48 am

Is this the right way round? If so, when I press the button the Arduino turns off (ON LED turns off) and it disconnects from my computer?
Attachments
Screenshot (293).png
Screenshot (293).png (149.87 KiB) Viewed 73 times

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 9:09 am

No.

Connect one side of the switch to 5v.
Connect the other side of the switch to pin 13.
Connect the resistor between pin 13 and GND.

adafruit_support_bill
 
Posts: 81308
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 9:20 am

Like this?
Attachments
Screenshot (294).png
Screenshot (294).png (150.44 KiB) Viewed 70 times

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 9:38 am

Connect the resistor directly to GND - not through the switch.

adafruit_support_bill
 
Posts: 81308
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 9:45 am

Like this?
Attachments
Screenshot (295).png
Screenshot (295).png (148.17 KiB) Viewed 69 times

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

Please be positive and constructive with your questions and comments.