|
@@ -7,9 +7,14 @@ Atm_fade_WS2812::Atm_fade_WS2812( CRGB *_leds, int _num_leds, int _offset_leds)
|
|
|
num_leds = _num_leds ;
|
|
|
offset_leds = _offset_leds ;
|
|
|
leds = _leds + offset_leds ;
|
|
|
+ leds_buffer = new CRGB[num_leds] ;
|
|
|
|
|
|
} ;
|
|
|
|
|
|
+ Atm_fade_WS2812::~Atm_fade_WS2812 (void) {
|
|
|
+ delete[] leds_buffer ;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
Atm_fade_WS2812& Atm_fade_WS2812::begin( ) {
|
|
|
// clang-format off
|
|
@@ -250,171 +255,46 @@ void Atm_fade_WS2812::update_leds(float fade_value){
|
|
|
CHSV temp_led[this->num_leds] ;
|
|
|
int current_value = color.val ;
|
|
|
|
|
|
- if(_replace_array){
|
|
|
- if(_fade_light){ current_value = color.val*fade_value ;}
|
|
|
- current_value = constrain(current_value, 0, 255 ) ;
|
|
|
- for(int led=0; led<num_leds; led++){
|
|
|
- // Serial.println(led);
|
|
|
- fade_value = _fade_chase ? fade_value : 1. ;
|
|
|
- if(led<fade_value*num_leds){
|
|
|
- temp_led[led].value = current_value ;
|
|
|
- temp_led[led].saturation = color.saturation ;
|
|
|
- temp_led[led].hue = color.hue ;
|
|
|
- }
|
|
|
- else{
|
|
|
- temp_led[led].value = 0 ;
|
|
|
- temp_led[led].saturation = color.saturation ;
|
|
|
- temp_led[led].hue = color.hue ;
|
|
|
- }
|
|
|
+ if(_fade_light){ current_value = color.val*fade_value ;}
|
|
|
+ current_value = constrain(current_value, 0, 255 ) ;
|
|
|
+ for(int led=0; led<num_leds; led++){
|
|
|
+ // Serial.println(led);
|
|
|
+ fade_value = _fade_chase ? fade_value : 1. ;
|
|
|
+ if(led<fade_value*num_leds){
|
|
|
+ temp_led[led].value = current_value ;
|
|
|
+ temp_led[led].saturation = color.saturation ;
|
|
|
+ temp_led[led].hue = color.hue ;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ temp_led[led].value = 0 ;
|
|
|
+ temp_led[led].saturation = color.saturation ;
|
|
|
+ temp_led[led].hue = color.hue ;
|
|
|
+ }
|
|
|
+ if(_replace_array){
|
|
|
if(reverse){leds[num_leds-led-1] = CRGB(temp_led[led]);}
|
|
|
else{leds[led] = CRGB(temp_led[led]);}
|
|
|
}
|
|
|
- }
|
|
|
- if(!_replace_array){
|
|
|
- CRGB colorRGB = CRGB(color);
|
|
|
-
|
|
|
-
|
|
|
- // current_value = constrain(current_value, 0, 255 ) ;
|
|
|
- CRGB temp_led_RGB[num_leds] ;
|
|
|
- for(int led=0; led<num_leds; led++){
|
|
|
- if(_fade_light){ colorRGB = colorRGB*fade_value/(FADE_STEPS*(1-led/num_leds));}
|
|
|
- fade_value = _fade_chase ? fade_value : 1. ;
|
|
|
-
|
|
|
- if(led<fade_value*num_leds){
|
|
|
- int current_led = reverse ? num_leds-led-1 : led ;
|
|
|
- if(this->state() == DOWN || this->state() == ODOWN) {
|
|
|
- leds[current_led].r = qsub8 (leds[current_led].r, colorRGB.r+1);
|
|
|
- leds[current_led].g = qsub8 (leds[current_led].g, colorRGB.g+1);
|
|
|
- leds[current_led].b = qsub8 (leds[current_led].b, colorRGB.b+1);
|
|
|
- }
|
|
|
- else{
|
|
|
- leds[current_led].r = qadd8 (leds[current_led].r, colorRGB.r);
|
|
|
- leds[current_led].g = qadd8 (leds[current_led].g, colorRGB.g);
|
|
|
- leds[current_led].b = qadd8 (leds[current_led].b, colorRGB.b);
|
|
|
- }
|
|
|
+ if(!_replace_array){
|
|
|
+ int current_led = reverse ? num_leds-led-1 : led ;
|
|
|
+ CRGB temp_led_RGB ;
|
|
|
+ if(this->state() == DOWN || this->state() == ODOWN) {
|
|
|
+ temp_led_RGB = leds_buffer[led]-CRGB(temp_led[led]);
|
|
|
+ leds[current_led].r = qsub8 (leds[current_led].r, temp_led_RGB.r);
|
|
|
+ leds[current_led].g = qsub8 (leds[current_led].g, temp_led_RGB.g);
|
|
|
+ leds[current_led].b = qsub8 (leds[current_led].b, temp_led_RGB.b);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ temp_led_RGB = CRGB(temp_led[led]) - leds_buffer[led];
|
|
|
+ leds[current_led].r = qadd8 (leds[current_led].r, temp_led_RGB.r);
|
|
|
+ leds[current_led].g = qadd8 (leds[current_led].g, temp_led_RGB.g);
|
|
|
+ leds[current_led].b = qadd8 (leds[current_led].b, temp_led_RGB.b);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // if(!_replace_array){
|
|
|
- // //add or remove one step of color
|
|
|
- // current_value = color.val / (FADE_STEPS-1) ;
|
|
|
- // if(reverse){
|
|
|
- // if(led>fade_value*num_leds){temp_led[led].value = current_value ;}
|
|
|
- // else{temp_led[led].value = 0 ;}
|
|
|
- // }
|
|
|
- // else{
|
|
|
- // if(led<fade_value*num_leds){temp_led[led].value = current_value ;}
|
|
|
- // else{temp_led[led].value = 0 ;}
|
|
|
- // }
|
|
|
|
|
|
- // // temp_led[led].value = current_value ;
|
|
|
- // // temp_led[led].value = temp_led[led].value / FADE_STEPS ;
|
|
|
- // temp_led[led].saturation = color.saturation ;
|
|
|
- // temp_led[led].hue = color.hue ;
|
|
|
- // if(update_flag){
|
|
|
- // CRGB rgb_step ;
|
|
|
- // if(reverse){ rgb_step= CRGB(temp_led[num_leds-led]) ;}
|
|
|
- // else{ rgb_step = CRGB(temp_led[led]) ;}
|
|
|
-
|
|
|
- // if(this->state() == DOWN || this->state() == ODOWN) {
|
|
|
- // // Serial.println("down");
|
|
|
- // leds[led].r = qsub8 (leds[led].r, rgb_step.r);
|
|
|
- // leds[led].g = qsub8 (leds[led].g, rgb_step.g);
|
|
|
- // leds[led].b = qsub8 (leds[led].b, rgb_step.b);
|
|
|
- // }
|
|
|
- // else{
|
|
|
- // leds[led].r = qadd8 (leds[led].r, rgb_step.r);
|
|
|
- // leds[led].g = qadd8 (leds[led].g, rgb_step.g);
|
|
|
- // leds[led].b = qadd8 (leds[led].b, rgb_step.b);
|
|
|
- // }
|
|
|
- // // leds[led] = blend(leds[led], CRGB(temp_led[led]), 255);
|
|
|
- // }
|
|
|
-
|
|
|
-
|
|
|
- // }
|
|
|
- Serial.println(leds[0].r);
|
|
|
+ }
|
|
|
+ hsv2rgb_rainbow(temp_led, leds_buffer, num_leds) ;
|
|
|
update_flag=true ;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-//was about working
|
|
|
-// if(update_flag){
|
|
|
-// // Serial.println("loop");
|
|
|
-// int current_step = fade_value * FADE_STEPS ;
|
|
|
-
|
|
|
-// CHSV temp_led[this->num_leds] ;
|
|
|
-// int current_value = color.val;
|
|
|
-
|
|
|
-// if(_fade_light){ current_value *= fade_value ;}
|
|
|
-
|
|
|
-// current_value = constrain(current_value, 0, 255 ) ;
|
|
|
-// // Serial.println(current_value);
|
|
|
-// int chase_led = num_leds;
|
|
|
-// for(int led=0; led<num_leds; led++){
|
|
|
-// // Serial.println(led);
|
|
|
-// fade_value = _fade_chase ? fade_value : 1. ;
|
|
|
-// if(led<fade_value*num_leds){
|
|
|
-// temp_led[led].value = current_value ;
|
|
|
-// temp_led[led].saturation = color.saturation ;
|
|
|
-// temp_led[led].hue = color.hue ;
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// temp_led[led].value = 0 ;
|
|
|
-// temp_led[led].saturation = color.saturation ;
|
|
|
-// temp_led[led].hue = color.hue ;
|
|
|
-// }
|
|
|
-
|
|
|
-// if(_replace_array){
|
|
|
-// if(reverse){leds[led] = CRGB(temp_led[num_leds-led]);}
|
|
|
-// else{leds[led] = CRGB(temp_led[led]);}
|
|
|
-// }
|
|
|
-// if(!_replace_array){
|
|
|
-// //add or remove one step of color
|
|
|
-// current_value = color.val / (FADE_STEPS-1) ;
|
|
|
-// if(reverse){
|
|
|
-// if(led>fade_value*num_leds){temp_led[led].value = current_value ;}
|
|
|
-// else{temp_led[led].value = 0 ;}
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// if(led<fade_value*num_leds){temp_led[led].value = current_value ;}
|
|
|
-// else{temp_led[led].value = 0 ;}
|
|
|
-// }
|
|
|
-
|
|
|
-// // temp_led[led].value = current_value ;
|
|
|
-// // temp_led[led].value = temp_led[led].value / FADE_STEPS ;
|
|
|
-// temp_led[led].saturation = color.saturation ;
|
|
|
-// temp_led[led].hue = color.hue ;
|
|
|
-// if(update_flag){
|
|
|
-// CRGB rgb_step ;
|
|
|
-// if(reverse){ rgb_step= CRGB(temp_led[num_leds-led]) ;}
|
|
|
-// else{ rgb_step = CRGB(temp_led[led]) ;}
|
|
|
-
|
|
|
-// if(this->state() == DOWN || this->state() == ODOWN) {
|
|
|
-// // Serial.println("down");
|
|
|
-// leds[led].r = qsub8 (leds[led].r, rgb_step.r);
|
|
|
-// leds[led].g = qsub8 (leds[led].g, rgb_step.g);
|
|
|
-// leds[led].b = qsub8 (leds[led].b, rgb_step.b);
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// leds[led].r = qadd8 (leds[led].r, rgb_step.r);
|
|
|
-// leds[led].g = qadd8 (leds[led].g, rgb_step.g);
|
|
|
-// leds[led].b = qadd8 (leds[led].b, rgb_step.b);
|
|
|
-// }
|
|
|
-// // leds[led] = blend(leds[led], CRGB(temp_led[led]), 255);
|
|
|
-// }
|
|
|
-// Serial.println(leds[0].r);
|
|
|
-
|
|
|
-
|
|
|
-// }
|
|
|
-// }
|
|
|
-// update_flag=true ;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// #endif
|
|
|
+}
|