diff --git a/achterbahn.ino b/achterbahn.ino index 9d3a63a..50c1eeb 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -24,6 +24,10 @@ long lastCheckspawn=0; #define CHECKSPAWNDELAY 4000 //delay in ms to check random spawn #define SPAWNCHANCE 20 //1 out of x times wagon will spawn #define SPAWNCHANCEDOUBLE 5 //change of spawning a two trains simultaneously +long lastCheckspawnEffect=0; +#define CHECKSPAWNDELAY_EFFECT 2000 //delay in ms to check random effect +#define SPAWNCHANCE_EFFECT_SCANNER 100 //1 out of x times spawn effect +#define SPAWNCHANCE_EFFECT_FLASH 80 //1 out of x times spawn effect #define BRIGHTNESS_RUN 200 #define BRIGHTNESS_DEBUG 150 @@ -389,7 +393,7 @@ void checkSerial(){ effect=new FX_Scanner(NUMPIXELS,&strip,height,255,-200,strip.Color(100,0,0)); }else if (serialstring.equals("fx_flash")){ Serial.println("Effect Flash"); - effect=new FX_Flash(NUMPIXELS,&strip,strip.Color(200,200,200)); + effect=new FX_Flash(NUMPIXELS,&strip,height,strip.Color(200,200,200)); } } @@ -494,11 +498,18 @@ void loop_achterbahn(){ if (random(0,SPAWNCHANCEDOUBLE)==0){ spawnWagon(); } - }//else{ - //Serial.println("no spawn"); - //} - - + } + } + + + //Check Effect Spawning + if (effect==NULL && lastCheckspawnEffect+CHECKSPAWNDELAY_EFFECT> 16; - uint8_t _g = _flashcolor >> 8; - uint8_t _b = _flashcolor; + if (_height[i]>=STARTFLASHHEIGHT){ + uint8_t heightbrightness=map(_height[i],STARTFLASHHEIGHT,BRIGHTFLASHHEIGHT,0,255); + + uint8_t _r = _flashcolor >> 16; + uint8_t _g = _flashcolor >> 8; + uint8_t _b = _flashcolor; + + _r*=_brightness/255.0; + _g*=_brightness/255.0; + _b*=_brightness/255.0; - - 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; + _r*=heightbrightness/255.0; + _g*=heightbrightness/255.0; + _b*=heightbrightness/255.0; + + + 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 } - 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){ + if (millis()-_starttime>_flashtime){ return false; } return true; diff --git a/fx_flash.h b/fx_flash.h index 95162ee..1b209c0 100644 --- a/fx_flash.h +++ b/fx_flash.h @@ -7,7 +7,7 @@ class FX_Flash : public Effect { public: - FX_Flash(int numpixels,Adafruit_NeoPixel *strip,uint32_t flashcolor); + FX_Flash(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height,uint32_t flashcolor); FX_Flash(); void updateRoutine(float updatedelayms); void updateGraphics(); @@ -18,6 +18,9 @@ class FX_Flash : public Effect Adafruit_NeoPixel *_strip; uint32_t _flashcolor; long _starttime; + uint8_t _brightness; + long _flashtime; + uint8_t *_height; }; #endif