#include <FastLED.h>
#define LED_PIN 2
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600); // Set the baud rate to 9600
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS); // Εδώ πέρα αλλάζω σε GRB για να εμφανίζει σωστά.
}
void loop() {
CRGB *colors = new CRGB[4]{CRGB::Red, CRGB::Green, CRGB::Blue, CRGB(145,67,200)};
// swapSolidColors(colors, leds, 4, 2000);
// swapSolidBreathing(colors, leds, 4, 100, 15);
shiftSolidColors(colors, leds, 4, 100, 20);
}
/*
-------------------------------
ALL RGB COLOR FUNCTIONS HERE
-------------------------------
*/
void setSolidColor(CRGB color, CRGB *leds){
for (int i=0; i<NUM_LEDS; i++){
leds[i] = color;
}
FastLED.show();
}
void setSolidBrightness(CRGB color, CRGB *leds, uint8_t brightness){
color = color %= brightness;
setSolidColor(color, leds);
}
void setSolidFadeIn(CRGB color, CRGB *leds, int &brightness, uint8_t speed, uint8_t step){
if(brightness<0) brightness=0;
while(brightness < 256){
setSolidBrightness(color, leds, brightness);
delay(speed);
brightness += step;
}
}
void setSolidFadeOut(CRGB color, CRGB *leds, int &brightness, uint8_t speed, uint8_t step){
if(brightness>255) brightness=255;
while(brightness >= 0){
setSolidBrightness(color, leds, brightness);
delay(speed);
brightness -= step;
}
}
void solidBreathing(CRGB color, CRGB *leds, int speed, uint8_t step){
int brightness = 0;
setSolidFadeIn(color, leds, brightness, speed, step);
setSolidFadeOut(color, leds, brightness, speed, step);
}
CRGB interpolateColor(CRGB startColor, CRGB endColor, float ratio) {
uint8_t r = startColor.r + (endColor.r - startColor.r) * ratio;
uint8_t g = startColor.g + (endColor.g - startColor.g) * ratio;
uint8_t b = startColor.b + (endColor.b - startColor.b) * ratio;
return CRGB(r, g, b);
}
void transitionColors(CRGB startColor, CRGB endColor, CRGB *leds, int speed, int steps) {
for (int step = 0; step <= steps; step++) {
float ratio = float(step) / steps;
CRGB currentColor = interpolateColor(startColor, endColor, ratio);
setSolidColor(currentColor, leds);
delay(speed);
}
}
// ------------------
void swapSolidColors(CRGB *colors, CRGB *leds, uint8_t num_colors, int speed){
for (int i=0; i<num_colors; i++){
setSolidColor(colors[i], leds);
delay(speed);
}
}
void swapSolidBreathing(CRGB *colors, CRGB *leds, uint8_t num_colors, int speed, uint8_t step){
for (int i=0; i<num_colors; i++){
solidBreathing(colors[i], leds, speed, step);
delay(speed);
}
}
void shiftSolidColors(CRGB *colors, CRGB *leds, uint8_t num_colors, int speed, int steps){
for (int i=0; i<num_colors; i++){
if(i<= num_colors-2){
transitionColors(colors[i], colors[i+1], leds, speed, steps);
}
else{
transitionColors(colors[i], colors[0], leds, speed, steps);
}
delay(speed);
}
}
/*
-------------------------------
END RGB COLOR FUNCTIONS
-------------------------------
*/
/*
-------------------------------
ALL ADDRESSIBLE RGB COLOR FUNCTIONS HERE
-------------------------------
*/