Jump to content

[NeoPixel Rainbow] I Can't Arduino, Send Help

Hackentosher

So I am trying to get 20 Adafruit Neopixels wired like a strip to fade through the rainbow. I tried taking the rainbow function from the strandtest example in the Neopixel library and inserting it into a new sketch, but that doesn't want to work.

Spoiler

#include <Adafruit_NeoPixel.h>
 #define PIN 6 
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800); 
 void setup() {
  strip.begin();
  strip.show(); 
   
 }
 void loop() {
     strip.setBrightness(191);
void rainbow(uint8_t wait);

  uint16_t i, j;

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

 
  }

 

 

Right now, the error I get in the compiler is " 'wheel' was not declared in this scope." So... I have basically no experience with Arduino, what am I doing wrong?

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

Update, following a guide led me to this code, but I'm still getting " '______' was not declared in this scope" bull shit. 

 

Updated code:

Spoiler

#include <Adafruit_NeoPixel.h>
 #define PIN 6 //change this to 0 or 1 for the Gemma
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800); //change this to 20
 void setup() {
  strip.begin();
  {
      // Initialize for a RainbowCycle
    void RainbowCycle(uint8_t interval);
    
       ActivePattern = RAINBOW_CYCLE;
        Interval = interval;
        TotalSteps = 255;
        Index = 0;
        Direction = dir;
    
  strip.show(); //turns all the pixels off
   
 }
 void loop() 
 
     strip.setBrightness(191);
void RainbowCycleUpdate()

  for(int i=0; i< numPixels(); i++)
  {
    setPixelColor(i, Wheel((i * 256 / numPixels()) + Index) & 255));
  }

 

 

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/10/2016 at 3:54 AM, Unimportant said:

"Wheel" is a function that your code tries to call but was never defined.

You need to add the Wheel function to the top of your code.

 

I'm guessing it's the function on lines 121 to 134 in this file:

https://github.com/adafruit/Adafruit_NeoPixel/blob/master/examples/strandtest/strandtest.ino

Alright, whenever it raised an error about something not being declared, I added int ______; and that seems to have resolved the errors. Not sure if it will work for my project, but it fixed the definition issues.

 

Now I'm having another issue because I have no clue what I'm doing,

Spoiler

#include <Adafruit_NeoPixel.h>
 #define PIN 6 //change this to 0 or 1 for the Gemma
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800); //change this to 20
   // Initialize for a RainbowCycle
int ActivePattern; 
int RAINBOWCYCLE;
int Interval = 500;
int TotalSteps = 255;
int Index = 0;
int Direction;   
int dir; 
int numPixels = 9;

 void setup() {
  strip.begin();
     void RainbowCycle(uint8_t interval);
  {
       ActivePattern = RAINBOWCYCLE;
       Interval = 500;
       TotalSteps = 255;
       Index = 0;
       Direction = dir;
   
  strip.show(); //turns all the pixels off
  }
 
 void loop();
 
     strip.setBrightness(191);
void RainbowCycleUpdate();

  for(int i=0; i< numPixels (); i++)
  {
    setPixelColor(i, Wheel((i * 256 / numPixels()) + Index) & 255));
  }

 

and it's raising an error on line 34 (that last one there) saying that numPixels can't be used as a function. When removed, it raises the same error on line 32 right above it. Did I define numPixels incorrectly?

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

One defines a function as such:

 

Return_type  function_name(parameters) { body_code }

 

One calls said function like this:

 

function_name(parameters);

 

Thus:

//This defines a function called "setup" which returns nothing (void) and takes no parameters...
void setup() {
  strip.begin();
  
  //Here you try to define a function "RainbowCycle" within the function "setup" which is impossible...
  //You cannot define a function within a function.
  void RainbowCycle(uint8_t interval);
  {
       ActivePattern = RAINBOWCYCLE;
       Interval = 500;
       TotalSteps = 255;
       Index = 0;
       Direction = dir;
   
  strip.show(); 
  }
  
  //Here you try to define a function "loop" wich returns nothing and takes no parameters,
  //but the function has no body "{}". If you want to call an already existing function called "loop" then simply write
  //  loop();
  //If you want to define a new function called "loop" then write
  //  void loop() { code }
  //But just like with function "RainbowCycle" we are still inside the body of function "setup" over here.
  void loop();
 
     strip.setBrightness(191);
  
//Same as before...  
void RainbowCycleUpdate();

  //Here, "numPixels" is a variable, but by adding the "()" you make the compiler think you're trying to call
  //a function called "numPixels" which takes no parameters. Simply write:
  // for (int i = 0; i < numPixels; i++)
  for(int i=0; i< numPixels (); i++)
  {
    //Same here:
    //setPixelColor(i, Wheel((i * 256 / numPixels) + Index) & 255));
    setPixelColor(i, Wheel((i * 256 / numPixels()) + Index) & 255));
  }
 

You also have no "main" function, which is where execution starts. Is this just part of your program or the full program?

Link to comment
Share on other sites

Link to post
Share on other sites

28 minutes ago, Unimportant said:

snip

Yeah this is the full program. As I said, I haven't the slightest clue what I'm doing.

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

On 12 August 2016 at 7:25 AM, Hackentosher said:

Alright, whenever it raised an error about something not being declared, I added int ______; and that seems to have resolved the errors. Not sure if it will work for my project, but it fixed the definition issues.

 

Now I'm having another issue because I have no clue what I'm doing,

  Hide contents


#include <Adafruit_NeoPixel.h>
 #define PIN 6 //change this to 0 or 1 for the Gemma
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800); //change this to 20
   // Initialize for a RainbowCycle
int ActivePattern; 
int RAINBOWCYCLE;
int Interval = 500;
int TotalSteps = 255;
int Index = 0;
int Direction;   
int dir; 
int numPixels = 9;

 void setup() {
  strip.begin();
     void RainbowCycle(uint8_t interval);
  {
       ActivePattern = RAINBOWCYCLE;
       Interval = 500;
       TotalSteps = 255;
       Index = 0;
       Direction = dir;
   
  strip.show(); //turns all the pixels off
  }
 
 void loop();
 
     strip.setBrightness(191);
void RainbowCycleUpdate();

  for(int i=0; i< numPixels (); i++)
  {
    setPixelColor(i, Wheel((i * 256 / numPixels()) + Index) & 255));
  }

 

 

and it's raising an error on line 34 (that last one there) saying that numPixels can't be used as a function. When removed, it raises the same error on line 32 right above it. Did I define numPixels incorrectly?

int numPixels = 9

^ numPixels can't be used as a function because you've defined it as an integer variable. I'm guessing that you are infact trying to use it as a variable, and not a function. So in that case, change your for loop to this: 

 

  for(int i=0; i<numPixels; i++)
  {
    setPixelColor(i, Wheel((i * 256 / numPixels) + Index) & 255));
  }

 

"Wait for the 1080ti" - they said.

Link to comment
Share on other sites

Link to post
Share on other sites

On 8/13/2016 at 6:40 PM, SnowCore said:

int numPixels = 9

^ numPixels can't be used as a function because you've defined it as an integer variable. I'm guessing that you are infact trying to use it as a variable, and not a function. So in that case, change your for loop to this: 

 


  for(int i=0; i<numPixels; i++)
  {
    setPixelColor(i, Wheel((i * 256 / numPixels) + Index) & 255));
  }

 

Hmm, when I remove

int numPixels = 9

it raises an error because numPixels wasn't declared. Removing int says that numPixels isn't a type. 

 

Edit: This is the most recent version of the code, and it's raising an error on line 36 saying that Wheel can't be used as a function. Since I have no idea how C works, please help :3

Spoiler

#include <Adafruit_NeoPixel.h>
 #define PIN 6 //change this to 0 or 1 for the Gemma
 Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800); //change this to 20
   // Initialize for a RainbowCycle
int ActivePattern; 
int RAINBOWCYCLE;
int Interval = 500;
int TotalSteps = 255;
int Index = 0;
int Direction;   
int dir; 
int numPixels = 9;
int Wheel;

   
 void setup() {
  strip.begin();
     void RainbowCycle(uint8_t interval);
  {
       ActivePattern = RAINBOWCYCLE;
       Interval = 500;
       TotalSteps = 255;
       Index = 0;
       Direction = dir;
   
  strip.show(); //turns all the pixels off
  }
 
 void loop();
 
     strip.setBrightness(191);
void RainbowCycleUpdate();

   for(int i=0; i<numPixels; i++)
  {
    setPixelColor(i, Wheel((i * 256 / numPixels) + Index) & 255));
  }
 }

 

 

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

On 22 August 2016 at 6:48 AM, Hackentosher said:

Hmm, when I remove


int numPixels = 9

it raises an error because numPixels wasn't declared. Removing int says that numPixels isn't a type. 

 

That's right, you need to declare it as a variable because you're using it as a variable. Simply, numPixels is a variable that you are assigning a value to (9 in this case), and then the function setPixelColor is using that value. 

What happens when you run the un-edited strandtest.ino sketch below? 

 

#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.show(); // Initialize all pixels to 'off'
}

void loop() {
  // 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) {
  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);
}

 

"Wait for the 1080ti" - they said.

Link to comment
Share on other sites

Link to post
Share on other sites

50 minutes ago, SnowCore said:

That's right, you need to declare it as a variable because you're using it as a variable. Simply, numPixels is a variable that you are assigning a value to (9 in this case), and then the function setPixelColor is using that value. 

What happens when you run the un-edited strandtest.ino sketch below? 

 


#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.show(); // Initialize all pixels to 'off'
}

void loop() {
  // 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) {
  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);
}

 

Strand test works, but when I tried to take out all the bits of that code I (thought I) didn't need, it didn't work, raised errors all over the place. 

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

So what exactly are you trying to do that the strandtest doesn't?

Doesn't strandtest cycle it's pixels through the rainbow? 

"Wait for the 1080ti" - they said.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, SnowCore said:

So what exactly are you trying to do that the strandtest doesn't?

Doesn't strandtest cycle it's pixels through the rainbow? 

Strandtest does a few more things I don't want it to do. 

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Hackentosher said:

Strandtest does a few more things I don't want it to do. 

Which is? I'll show you which parts to remove.

"Wait for the 1080ti" - they said.

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, SnowCore said:

Which is? I'll show you which parts to remove.

I'll have to get a video my 3x3 matrix running the program, gimme a few. 

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

  • 5 weeks later...
On 8/22/2016 at 6:20 PM, SnowCore said:

Which is? I'll show you which parts to remove.

Wow, I'm great at following through with promises, basically I want the arduino to give the same effect as all the RGB keyboards, with a rainbow fading down the strip.

ASU

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×