Theudas

led.h

Mar 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. class Led{
  2.   public:
  3.    
  4.     float brightness;
  5.     float bis;
  6.     float bsoll;
  7.  
  8.     float hue;
  9.     float his;
  10.     float hsoll;
  11.  
  12.   NeoGamma<NeoGammaTableMethod> colorGamma;
  13.    
  14.     CRGB fastcolor;
  15.    
  16.     RgbColor color;
  17.     RgbColor coloris = RgbColor(0,0,0);
  18.     RgbColor colorsoll;
  19.  
  20.     uint8_t animation = 1;
  21.    
  22.     uint8_t x;
  23.     uint8_t y;
  24.     uint8_t xscale = 12;
  25.     uint8_t yscale = 8;
  26.     uint8_t timescale = 1;
  27.  
  28.     // only update the new color every [interpoation] frame and interpolate between
  29.     uint8_t interpolation = 20;
  30.    
  31.    
  32.     void Set(uint8_t x, uint8_t y);
  33.     uint8_t shine(uint16_t t);
  34.     uint8_t flame(uint16_t t);
  35.     uint8_t bright(uint16_t t);
  36.     RgbColor paint(uint16_t counter);
  37.    
  38. };
  39.  
  40. void Led::Set(uint8_t x, uint8_t y){
  41.     this->x = x;
  42.     this->y = y;
  43. }
  44.  
  45. RgbColor Led::paint(uint16_t counter){
  46.   uint8_t btemp;
  47.   uint8_t huetemp;
  48.  
  49.   // check if new color needs to be generated
  50.   if(counter % interpolation == 0){
  51.     //switch between animations
  52.     switch(this->animation){
  53.       case 0:
  54.         btemp = this->bright(counter / interpolation);
  55.         huetemp = btemp + (counter / interpolation / 4);
  56.       break;
  57.      
  58.       case 1:
  59.         btemp = this->flame(counter / interpolation);
  60.         huetemp = btemp + (counter / interpolation / 4);
  61.       break;
  62.      
  63.       default:
  64.       break;
  65.     }
  66.  
  67.     // center the maximum brightness around the middle values of inoise8
  68.     this->bis = this->bsoll;
  69.     if(btemp >= 128)
  70.       btemp = (255 - btemp)*2;
  71.     else
  72.       btemp *= 2;
  73.      
  74.    
  75.     // set a new color
  76.     this->color = this->colorsoll;
  77.     this->coloris = this->colorsoll;
  78.    
  79.     this->fastcolor.setHSV(huetemp, 255, btemp);    
  80.     this->colorsoll = colorGamma.Correct(RgbColor(this->fastcolor.r, this->fastcolor.g, this->fastcolor.b));
  81.    
  82.   }else{
  83.     //ramp between coloris to colorsoll
  84.     this->color = RgbColor::LinearBlend(this->coloris, this->colorsoll, (counter % interpolation)*(1.0/interpolation));
  85.   }
  86.  
  87.   return this->color;
  88. }
  89.  
  90. uint8_t Led::shine(uint16_t t){
  91.   return inoise8(this->x * this->xscale, this->y * this->yscale, t * this->timescale);
  92. }
  93.  
  94. uint8_t Led::flame(uint16_t t){
  95.   return inoise8(this->x * this->xscale, (this->y - t) * this->yscale , t * this->timescale);
  96. }
  97.  
  98. uint8_t Led::bright(uint16_t t){
  99.   return inoise8(this->x * this->xscale, this->y * this->yscale, t * this->timescale);
  100. }
Advertisement
Add Comment
Please, Sign In to add comment