From 0da6f7a29df7147beda16127030fc72c8be45487 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 23 Dec 2016 01:43:06 +0100 Subject: [PATCH] new effect randomfade, added a few effect parameters and commands --- pixelprojektor/pixelprojektor.ino | 84 +++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/pixelprojektor/pixelprojektor.ino b/pixelprojektor/pixelprojektor.ino index 0abad6b..5da146f 100644 --- a/pixelprojektor/pixelprojektor.ino +++ b/pixelprojektor/pixelprojektor.ino @@ -17,7 +17,13 @@ uint8_t effect=0; uint8_t movingPoint_x=3; uint8_t movingPoint_y=3; uint8_t wheelPos=0; +uint8_t wheelPosSlow=0; //for slower wheelPos increment than 1 +int wheelSpeed=16; //16=+1/frame +int smoothing=80; //0 to 100. 100=no change (ultrasmooth), 0=no smoothing. +int strength=50; //how much pixels to apply color to #define EFFECT_SPIRAL 2 +#define EFFECT_RANDOMFADE 3 +int fadespeedmax=5; //1 to 255 @@ -137,10 +143,10 @@ uint8_t getAverage(uint8_t array[NUMPIXELS], uint8_t i, int x, int y) void led_smooth() { for (int i=0; i < strip.numPixels(); i++) { - uint8_t avgbrightness=pixelR_buffer[i]/3+pixelG_buffer[i]/3+pixelB_buffer[i]/3; - pixelR_buffer[i]=0.8*pixelR[i] + 0.2*getAverage(pixelR,i, 0,0); - pixelG_buffer[i]=0.8*pixelG[i] + 0.2*getAverage(pixelG,i, 0,0); - pixelB_buffer[i]=0.8*pixelB[i] + 0.2*getAverage(pixelB,i, 0,0); + //uint8_t avgbrightness=pixelR_buffer[i]/3+pixelG_buffer[i]/3+pixelB_buffer[i]/3; + pixelR_buffer[i]=(smoothing/100.0)*pixelR[i] + (1.0-(smoothing/100.0))*getAverage(pixelR,i, 0,0); + pixelG_buffer[i]=(smoothing/100.0)*pixelG[i] + (1.0-(smoothing/100.0))*getAverage(pixelG,i, 0,0); + pixelB_buffer[i]=(smoothing/100.0)*pixelB[i] + (1.0-(smoothing/100.0))*getAverage(pixelB,i, 0,0); } showBuffer(); @@ -149,7 +155,10 @@ void led_smooth() void led_movingPoint() { uint32_t c=wheel(wheelPos); - wheelPos=(wheelPos+1)%255; + wheelPosSlow+=wheelSpeed; + wheelPos=(wheelPos+ (wheelPosSlow/10) )%255; + wheelPosSlow=wheelPosSlow%16; + uint8_t r = (uint8_t)(c >> 16); uint8_t g = (uint8_t)(c >> 8); uint8_t b = (uint8_t)c; @@ -174,7 +183,7 @@ void led_movingPoint() uint8_t startx=movingPoint_x; uint8_t starty=movingPoint_y; - for (int i=0;i<50;i++){ + for (int i=0;i0){ + wheelSpeed=p1; + } + smoothing=80; + if (p2>0){ + smoothing=p2; + } + strength=50; + if (p3>0){ + strength=p3; + } + Homie.getLogger() << "-- p1=" << p1 << " p2=" << p2 << " p3=" << p3 << endl; effect=EFFECT_SMOOTH; bufferClear(); showBuffer(); @@ -298,6 +345,22 @@ bool effectHandler(const HomieRange& range, const String& value) { bufferClear(); showBuffer(); strip.show(); + }else if (command.equals("clearbuffer")){ + bufferClear(); + showBuffer(); + strip.show(); + }else if (command.equals("randomfade")){ //example: randomfade|5 + int sepparam = parameters.indexOf("|"); + int p1=parameters.substring(0,sepparam).toInt(); + fadespeedmax=5; + if (p1>0){ + fadespeedmax=p1; + } + effect=EFFECT_RANDOMFADE; + set_randomBuffer(); //initialize random + }else if (command.equals("randombuffer")){ + set_randomBuffer(); //set random + showBuffer(); } @@ -368,6 +431,9 @@ void loop() { case EFFECT_SPIRAL: led_spiral(); break; + case EFFECT_RANDOMFADE: + led_randomfade(); + break; } lastMillis=currentMillis;