From 1187c7f42bad9ab8416901b159e2ea31ad5dcea5 Mon Sep 17 00:00:00 2001 From: LGG Date: Fri, 29 May 2015 19:11:57 -0500 Subject: [PATCH 1/2] Add Ability to specify start hue and hue amount to affect all other effects Add Graphical effects to choose hue section. Allows rainbow effects to now be Fire/Ice/Valentines/Solid Color. --- RGBShades.ino | 4 ++- effects.h | 86 +++++++++++++++++++++++++++++++++++++++++++-------- utils.h | 30 ++++++++++++++++++ 3 files changed, 106 insertions(+), 14 deletions(-) diff --git a/RGBShades.ino b/RGBShades.ino index ca4a9cd..09e49e7 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -64,7 +64,9 @@ functionList effectList[] = {threeSine, colorFill, sideRain, shadesOutline, - hearts}; + hearts, + pickHueStartColor, + pickHueAmount}; // Timing parameters #define cycleTime 15000 diff --git a/effects.h b/effects.h index f966704..fb2bae6 100644 --- a/effects.h +++ b/effects.h @@ -13,8 +13,13 @@ void threeSine() { // startup tasks if (effectInit == false) { effectInit = true; - effectDelay = 20; + if(doHueSubsection)//Pause the effect to show the last saved hue amount + { + effectDelay = 600; + return; + } } + effectDelay = 20; // Draw one frame of the animation into the LED array for (byte x = 0; x < kMatrixWidth; x++) { @@ -57,7 +62,7 @@ void plasma() { for (int x = 0; x < kMatrixWidth; x++) { for (int y = 0; y < kMatrixHeight; y++) { byte color = sin8(sqrt(sq(((float)x-7.5)*10+xOffset-127)+sq(((float)y-2)*10+yOffset-127))+offset); - leds[XY(x,y)] = CHSV(color, 255, 255); + leds[XY(x,y)] = SectionCHSV(color, 255, 255); } } @@ -83,7 +88,7 @@ void rider() { int brightness = abs(x*(256/kMatrixWidth) - triwave8(riderPos)*2 + 127)*3; if (brightness > 255) brightness = 255; brightness = 255 - brightness; - CRGB riderColor = CHSV(cycleHue, 255, brightness); + CRGB riderColor = SectionCHSV(cycleHue, 255, brightness); for (byte y = 0; y < kMatrixHeight; y++) { leds[XY(x,y)] = riderColor; } @@ -107,7 +112,7 @@ void glitter() { // Draw one frame of the animation into the LED array for (int x = 0; x < kMatrixWidth; x++) { for (int y = 0; y (number * (255 / maxLeds))) + { + leds[XY(x, y)] = CHSV(((255. * number) / maxLeds) + hueOffset, 255, 255); + } + else + { + leds[XY(x, y)] = SectionCHSV(0, 0, 0); + } + } + } +} + diff --git a/utils.h b/utils.h index ecacc94..ea0c70c 100644 --- a/utils.h +++ b/utils.h @@ -25,6 +25,36 @@ void hueCycle(byte incr) { cycleHue+=incr; } +/* Instead of a perpetually incrimenting hue, override hue calculations to instead do a + * sinusodial loop back and forth over a smaller section of the scale. + * This can allow various effects, ice, hue, or even single colors. + * If the hue ammount is close to max, switch back to an incrimental mode and allow pallets + * to be used again. Continually incrimenting the offset and ammount allows the autoCycle + * mode to keep making new sections. + */ +//Keep making new effects. +byte hueOffset = 0;//The start hue for our cycle +byte hueAmmountIncrimentor = 0;//incrimentor for generating the hueAmmount +byte hueAmmount = 1;//The distance across the hue scale to allow sliding +bool doHueSubsection = false;//Switch to go back to a continuous hue slide (no more back & forth) +CHSV SectionCHSV(uint8_t h, uint8_t s, uint8_t v) +{ + //return a hue from a sinusodial wave across our current section of the hue scale + if (doHueSubsection)return CHSV((quadwave8(h) / (255. / hueAmmount)) + hueOffset, s, v); + return CHSV(h, s, v); +} +void incrimentHueOffset(uint8_t offset) +{ + hueOffset += offset; +} +void incrimentHueAmmount(uint8_t offset) +{ + hueAmmountIncrimentor += offset; + //Don't actually increase it till it loops to 0, instead make it go up, then back down. + hueAmmount = triwave8(hueAmmountIncrimentor); + doHueSubsection = hueAmmount < 230;//If the hue amount is almost a full rainbow, make it a full rainbow to allow pallet effects and others +} + // Set every LED in the array to a specified color void fillAll(CRGB fillColor) { for (byte i = 0; i < NUM_LEDS; i++) { From 36d8720b40232a3d54ac0dcb1c195704142768b1 Mon Sep 17 00:00:00 2001 From: LGG Date: Sat, 30 May 2015 18:00:19 -0500 Subject: [PATCH 2/2] Update the threeSin and threeDee effects to use hue section colors. --- effects.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/effects.h b/effects.h index fb2bae6..923f4f4 100644 --- a/effects.h +++ b/effects.h @@ -30,8 +30,20 @@ void threeSine() { byte sinDistanceR = qmul8(abs(y*(255/kMatrixHeight) - sin8(sineOffset*9+x*16)),2); byte sinDistanceG = qmul8(abs(y*(255/kMatrixHeight) - sin8(sineOffset*10+x*16)),2); byte sinDistanceB = qmul8(abs(y*(255/kMatrixHeight) - sin8(sineOffset*11+x*16)),2); - - leds[XY(x,y)] = CRGB(255-sinDistanceR, 255-sinDistanceG, 255-sinDistanceB); + + if(doHueSubsection) + { + CRGB firstColor = SectionCHSV(0, 255, 255); + CRGB secondColor = SectionCHSV(85, 255, 255); + CRGB thirdColor = SectionCHSV(170, 255, 255); + leds[XY(x,y)] = + firstColor.nscale8(255-sinDistanceR) + + secondColor.nscale8(255-sinDistanceG) + + thirdColor.nscale8(255-sinDistanceB); + }else + { + leds[XY(x,y)] = CRGB(255-sinDistanceR, 255-sinDistanceG, 255-sinDistanceB); + } } } @@ -187,9 +199,9 @@ void threeDee() { for (byte x = 0; x < kMatrixWidth; x++) { for (byte y = 0; y < kMatrixHeight; y++) { if (x < 7) { - leds[XY(x,y)] = CRGB::Blue; + leds[XY(x,y)] = SectionCHSV(170, 255, 255); } else if (x > 8) { - leds[XY(x,y)] = CRGB::Red; + leds[XY(x,y)] = SectionCHSV(0, 255, 255); } else { leds[XY(x,y)] = CRGB::Black; }