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

Awesome!!

I just checked with that configuration and it works perfectly, THANK YOU!!

However the only issue is that when it gets to the end with the swirling changing pattern it does not turn off on the next press of the button, any ideas?

Updated code:
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;
  } else if(buttonState == LOW) {
    prestate = 0;
  }

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 ;

  }
}

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 10:18 am

That is because you tell it to go back to the first pattern:
Code: Select all | TOGGLE FULL SIZE
    if ( count_value == 6) {
count_value = 0 ;

  }


If you want it to stop, then just do nothing when it reaches 6.

adafruit_support_bill
 
Posts: 81528
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 10:22 am

Ok,

I was more talking about the fact that when it reaches 5 and starts the rainbow animation it ignores everything else and stops on the rainbow animation so doesn't finish the rest of the script meaning it effectively cannot be turned off.

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 10:34 am

That is because your rainbow function takes a long tome to run. And while it is running, it isn't looking at the button.

You need to hold the button down long enough that it is still pressed before it starts the next cycle.

adafruit_support_bill
 
Posts: 81528
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 10:54 am

Yeah that should work,
Is there any way I can reduce that amount of time as I preferably wanted it to just be a single press, IE: a script that runs in the background?

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 11:01 am

There is no 'background' on the Arduino. If you want to multi-task, you need to change the structure of your program.

I have a 3-part tutorial on the subject here:

https://learn.adafruit.com/multi-taskin ... ino-part-1
https://learn.adafruit.com/multi-taskin ... ino-part-2
https://learn.adafruit.com/multi-taskin ... ino-part-3

adafruit_support_bill
 
Posts: 81528
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 11:18 am

I noticed in the tutorials it mentions the 'rainbow_cycle' command however I am using the 'rainbow' command which is slightly different, would it be possible to modify the interrupt code for the 'raibow_cycle' to 'rainbow'

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 11:46 am

The multitasking techniques described in the tutorial can be applied to any pattern you like.

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

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

by Ryan_S on Mon May 03, 2021 7:49 am

In the end I’ve decided to get rid of the rainbow as I didn’t really need it, however I am having an issue where when you press the button it goes through the process and to red however when it gets to red it does not turn off in the next click, instead it goes straight back to white at the beginning, it seems like it goes through to red (4) and instead of going to 5 which sends it back to 0 it jumps straight to 1?

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

Please be positive and constructive with your questions and comments.