add persistancemodes

This commit is contained in:
interfisch 2019-06-05 01:54:20 +02:00
parent 2417ae97ac
commit 4628d35770
2 changed files with 41 additions and 11 deletions

View File

@ -14,6 +14,7 @@
#include "fx_scanner.h"
#include "fx_flash.h"
#define PIN D2
#define NUMPIXELS 600
@ -51,6 +52,15 @@ uint8_t wagoncount=0;
Effect* effect = NULL;
//Persistance effects
#define PERSMODE_BLACK 0
#define PERSMODE_FADEPERCENT 1
#define NUM_PERSMODE 2 //number of available persistancemodes
uint8_t persistancemode=PERSMODE_BLACK;
long last_changePersistancemode=0;
#define PERSISTANCEMODECHANGE_DELAY 180000
//define config
//#define RESPAWNWAGON
@ -410,8 +420,36 @@ void loop_achterbahn(){
lastPixelUpdate=loopmillis;
for (int i=0;i<NUMPIXELS;i++){ //all black
uint32_t c=strip.Color(0,0,0);
strip.setPixelColor(i,c);
switch (persistancemode){
case PERSMODE_FADEPERCENT:
{
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;
uint32_t c=strip.Color(_pxr*0.99,_pxg*0.99,_pxb*0.99);
strip.setPixelColor(i,c);
break;
}
case PERSMODE_BLACK: default:
{
uint32_t c=strip.Color(0,0,0);
strip.setPixelColor(i,c);
break;
}
}
}
//possible persistancemode change
if (millis()>last_changePersistancemode+PERSISTANCEMODECHANGE_DELAY) {
if (random(0,10)!=0){
persistancemode = PERSMODE_BLACK;
}else{
persistancemode=random(1,NUM_PERSMODE);
}
last_changePersistancemode = millis();
}
//Wagons

View File

@ -305,15 +305,7 @@ void Wagon::updateGraphics()
_tmpr=(uint16_t)(min(255,_tmpr*_brightnesscorrection));
_tmpg=(uint16_t)(min(255,_tmpg*_brightnesscorrection));
_tmpb=(uint16_t)(min(255,_tmpb*_brightnesscorrection));
/*if (_tmpr>255){ //clamp
_tmpr=255;
}
if (_tmpg>255){
_tmpg=255;
}
if (_tmpb>255){
_tmpb=255;
}*/
_strip->setPixelColor(iCorrected,_tmpr,_tmpg,_tmpb); //draw pixel
}
}