#include <FastLED.h>
#define CATHODE 0
#define ANODE 1
class RGB_LED {
public:
RGB_LED(int red, int green, int blue, bool type){
this->red = red;
this->green = green;
this->blue = blue;
this->type = type;
}
void init(){
pinMode(this->red, OUTPUT);
pinMode(this->green, OUTPUT);
pinMode(this->blue, OUTPUT);
if(type){
digitalWrite(this->red, HIGH);
digitalWrite(this->green, HIGH);
digitalWrite(this->blue, HIGH);
}
}
void setColor(int r, int g, int b){
if(!type){
analogWrite(this->red, r);
analogWrite(this->green, g);
analogWrite(this->blue, b);
} else {
analogWrite(this->red, map(r, 0, 255, 255, 0));
analogWrite(this->green, map(g, 0, 255, 255, 0));
analogWrite(this->blue, map(b, 0, 255, 255, 0));
}
}
#ifdef FASTLED_VERSION
void setColor(CRGB crgb){
setColor(crgb.r, crgb.g, crgb.b);
}
#endif
private:
int red,green,blue;
bool type;
};
RGB_LED rgb(3,5,6, CATHODE);
#define NUM_LEDS 12
#define LED_PIN 2
CRGB leds[NUM_LEDS];
uint8_t hue = 0;
void setup(){
rgb.init();
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 );
FastLED.setBrightness(255);
}
void loop(){
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue, 255, 255);
rgb.setColor( CHSV(hue, 255, 255) );
}
EVERY_N_MILLISECONDS(15){
hue++;
}
FastLED.show();
}