60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
|
#include "fx_flash.h"
|
||
|
#include "effect.h"
|
||
|
|
||
|
#define FLASHTIME 10 //in ms
|
||
|
|
||
|
FX_Flash::FX_Flash(int numpixels,Adafruit_NeoPixel *strip,uint32_t flashcolor)
|
||
|
{
|
||
|
_numpixels=numpixels;
|
||
|
_strip=strip;
|
||
|
_flashcolor=flashcolor;
|
||
|
_starttime=millis();
|
||
|
}
|
||
|
|
||
|
FX_Flash::FX_Flash()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void FX_Flash::updateRoutine(float updatedelayms)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void FX_Flash::updateGraphics()
|
||
|
{
|
||
|
for(int i=0;i<_numpixels;i++){
|
||
|
|
||
|
uint8_t _r = _flashcolor >> 16;
|
||
|
uint8_t _g = _flashcolor >> 8;
|
||
|
uint8_t _b = _flashcolor;
|
||
|
|
||
|
|
||
|
uint32_t _pxcolor=_strip->getPixelColor(i); //get current color of that pixel
|
||
|
uint8_t _pxr = _pxcolor >> 16;
|
||
|
uint8_t _pxg = _pxcolor >> 8;
|
||
|
uint8_t _pxb = _pxcolor;
|
||
|
uint16_t _tmpr=_pxr+_r; //add colors
|
||
|
uint16_t _tmpg=_pxg+_g;
|
||
|
uint16_t _tmpb=_pxb+_b;
|
||
|
if (_tmpr>255){ //clamp
|
||
|
_tmpr=255;
|
||
|
}
|
||
|
if (_tmpg>255){
|
||
|
_tmpg=255;
|
||
|
}
|
||
|
if (_tmpb>255){
|
||
|
_tmpb=255;
|
||
|
}
|
||
|
_strip->setPixelColor(i,_tmpr,_tmpg,_tmpb); //draw pixel
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
bool FX_Flash::active()
|
||
|
{
|
||
|
if (millis()-_starttime>FLASHTIME){
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|