#include <FastLED.h>
#define PIN 2 // WS2812 pin
#define LED 4 // Number of WS2812
#define MAX 255 // Maximum brightness
CRGB leds[LED];
int oldred, oldgrn, oldblu, r, g, b, brightness = 1; // brightness divixor 1 - 255
void setup() {
Serial.begin(115200);
FastLED.addLeds<WS2812, PIN, GRB>(leds, LED);
FastLED.clear();
FastLED.setBrightness(MAX);
FastLED.show();
}
void loop() {
trim(); // adjust RGB colors
}
void trim() {
int r = map(analogRead(A0), 0, 1023, 255, 0);
int g = map(analogRead(A1), 0, 1023, 255, 0);
int b = map(analogRead(A2), 0, 1023, 255, 0);
r /= brightness; g /= brightness; b /= brightness; // adjust brightness
setColor(r, g, b);
if (r != oldred || g != oldgrn || b != oldblu) { // print changing values
printrgb(r, g, b);
}
oldred = r; oldgrn = g; oldblu = b; // store old values
}
void setColor(int red, int grn, int blu) { // first four pixels
leds[3] = CRGB(red, 000, 000); FastLED.show(); // red
leds[2] = CRGB(000, grn, 000); FastLED.show(); // grn
leds[1] = CRGB(000, 000, blu); FastLED.show(); // blu
leds[0] = CRGB(red, grn, blu); FastLED.show(); // rgb
}
void printrgb(int r, int g, int b) { // print analog values
Serial.print("red "); pad (r); Serial.print(r);
Serial.print(" grn "); pad (g); Serial.print(g);
Serial.print(" blu "); pad (b); Serial.print(b);
Serial.println();
}
void pad (int val) { // space pad analog value
if (val < 100) Serial.print(" ");
if (val < 10) Serial.print(" ");
}
red
grn
blu
red
grn
blu
rgb
1000uF
e.cap