i have a simple class, but he tells me that _bluePin, _greenPin and _redPin are out of scope(?) in the light.cpp in analogWrite(_bluePin, blue);
light.h
#ifndef light_h
#define light_h
#include "Arduino.h"
class light {
public:
light(int redPin, int greenPin, int bluePin);
void setColor(int red, int green, int blue);
private:
int _redPin;
int _greenPin;
int _bluePin;
};
#endif
light.cpp
/*
light.cpp
*/
#include "Arduino.h"
#include "light.h"
light::light(int r, int g, int b) {
_redPin = r;
_greenPin = g;
_bluePin = b;
}
void setColor(int red, int green, int blue) {
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(_redPin, red);
analogWrite(_greenPin, green);
analogWrite(_bluePin, blue);
}
You defined the pin numbers as private members of the class "light", which means that they are out of scope to anything that is not a member of "light".
The constructor "light::light" (hint) is a member of "light", but "setColor" is not.
AWOL:
You defined the pin numbers as private members of the class "light", which means that they are out of scope to anything that is not a member of "light".
The constructor "light::light" (hint) is a member of "light", but "setColor" is not.
aaaaaaaahh.. so you mean it should be
void light::setColor(int red, int green, int blue) {
??
Is setColor a method of your class? how do you declare a method (member functions of a class)?
i though so (??) oO ..
class light {
public:
light(int redPin, int greenPin, int bluePin);
void setColor(int red, int green, int blue);
...