Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Led{
- public:
- float brightness;
- float bis;
- float bsoll;
- float hue;
- float his;
- float hsoll;
- NeoGamma<NeoGammaTableMethod> colorGamma;
- CRGB fastcolor;
- RgbColor color;
- RgbColor coloris = RgbColor(0,0,0);
- RgbColor colorsoll;
- uint8_t animation = 1;
- uint8_t x;
- uint8_t y;
- uint8_t xscale = 12;
- uint8_t yscale = 8;
- uint8_t timescale = 1;
- // only update the new color every [interpoation] frame and interpolate between
- uint8_t interpolation = 20;
- void Set(uint8_t x, uint8_t y);
- uint8_t shine(uint16_t t);
- uint8_t flame(uint16_t t);
- uint8_t bright(uint16_t t);
- RgbColor paint(uint16_t counter);
- };
- void Led::Set(uint8_t x, uint8_t y){
- this->x = x;
- this->y = y;
- }
- RgbColor Led::paint(uint16_t counter){
- uint8_t btemp;
- uint8_t huetemp;
- // check if new color needs to be generated
- if(counter % interpolation == 0){
- //switch between animations
- switch(this->animation){
- case 0:
- btemp = this->bright(counter / interpolation);
- huetemp = btemp + (counter / interpolation / 4);
- break;
- case 1:
- btemp = this->flame(counter / interpolation);
- huetemp = btemp + (counter / interpolation / 4);
- break;
- default:
- break;
- }
- // center the maximum brightness around the middle values of inoise8
- this->bis = this->bsoll;
- if(btemp >= 128)
- btemp = (255 - btemp)*2;
- else
- btemp *= 2;
- // set a new color
- this->color = this->colorsoll;
- this->coloris = this->colorsoll;
- this->fastcolor.setHSV(huetemp, 255, btemp);
- this->colorsoll = colorGamma.Correct(RgbColor(this->fastcolor.r, this->fastcolor.g, this->fastcolor.b));
- }else{
- //ramp between coloris to colorsoll
- this->color = RgbColor::LinearBlend(this->coloris, this->colorsoll, (counter % interpolation)*(1.0/interpolation));
- }
- return this->color;
- }
- uint8_t Led::shine(uint16_t t){
- return inoise8(this->x * this->xscale, this->y * this->yscale, t * this->timescale);
- }
- uint8_t Led::flame(uint16_t t){
- return inoise8(this->x * this->xscale, (this->y - t) * this->yscale , t * this->timescale);
- }
- uint8_t Led::bright(uint16_t t){
- return inoise8(this->x * this->xscale, this->y * this->yscale, t * this->timescale);
- }
Advertisement
Add Comment
Please, Sign In to add comment