Go Down

Topic: Compiler Error - 'Color' was not declared in this scope (Read 1 time) previous topic - next topic

phil007

I'm getting the error 'Color' was not declared in this scope on the code below with c = Color(255,0,0); being highlighted. I'm trying to get the LPD8806 LED strips to run a color pattern from the center and I'm missing something that's preventing the code to compile.

Thanks,
Phil

Code: [Select]
   #include "LPD8806.h"
   #include "SPI.h"

   int dataPin = 2;  
   int clockPin = 3;
   const int numPixels = 32;

   LPD8806 strip = LPD8806(32, dataPin, clockPin);

   void loop() {
         int i;
         uint32_t c;

         // Set all pixels to red
         c = Color(255,0,0);
         for (i=0; i < strip.numPixels(); i++) {
             strip.setPixelColor(i, c);
         }
         strip.show();
         delay(100);

   
         // Wipe from middle:
         c = Color(255, 255, 255); // white
         for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
           strip.setPixelColor(i, c); // left pixel
           strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
           strip.show();
           delay(100);
         }
   }

dkl65

#1
May 19, 2012, 12:08 am Last Edit: May 19, 2012, 02:10 am by dkl65 Reason: 1
Uh-oh... where is the setup? Even if you don't use the setup, you must do this:
Code: [Select]
void setup(){
}

Oh right, on the line of c = Color(255,0,0); you need to do this instead:
Code: [Select]
c = strip.Color(255,0,0);
P.S. I replied 6 minutes after you posted!
Visit http://www.glenof.webs.com/!

Arrch

#2
May 19, 2012, 12:09 am Last Edit: May 19, 2012, 12:10 am by Arrch Reason: 1

I'm getting the error 'Color' was not declared in this scope on the code below with c = Color(255,0,0); being highlighted. I'm trying to get the LPD8806 LED strips to run a color pattern from the center and I'm missing something that's preventing the code to compile.

Looks like Color is a member function of the object created. Just as you did with all the other member functions, you need to tell the compiler which object to call that function for.

phil007

Quote
P.S. I replied 6 minutes after you posted!


And it works...thanks for the quick help!

Phil

wildbill

Quote
And the setup must be before the loop.

Most assuredly, not the case. Try it with the most trivial example.

dkl65

Quote
Most assuredly, not the case. Try it with the most trivial example.

Huh?
Visit http://www.glenof.webs.com/!

The Clever Monkey


Quote
Most assuredly, not the case. Try it with the most trivial example.

Huh?


The order of the standard function definitions does not matter:

Code: [Select]

void loop() {
   // Do nothing
}

void setup() {
  // WAT?
}


This code works fine.
I yield() for co-routines.

Go Up