|
| 1 | +/* |
| 2 | + ESP32 FastLED WebServer: https://github.com/jasoncoon/esp32-fastled-webserver |
| 3 | + Copyright (C) 2017 Jason Coon |
| 4 | +
|
| 5 | + Built upon the amazing FastLED work of Daniel Garcia and Mark Kriegsman: |
| 6 | + https://github.com/FastLED/FastLED |
| 7 | +
|
| 8 | + ESP32 support provided by the hard work of Sam Guyer: |
| 9 | + https://github.com/samguyer/FastLED |
| 10 | +
|
| 11 | + This program is free software: you can redistribute it and/or modify |
| 12 | + it under the terms of the GNU General Public License as published by |
| 13 | + the Free Software Foundation, either version 3 of the License, or |
| 14 | + (at your option) any later version. |
| 15 | +
|
| 16 | + This program is distributed in the hope that it will be useful, |
| 17 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + GNU General Public License for more details. |
| 20 | +
|
| 21 | + You should have received a copy of the GNU General Public License |
| 22 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | +*/ |
| 24 | +const CRGBPalette16 palettes[] = { |
| 25 | + RainbowColors_p, |
| 26 | + RainbowStripeColors_p, |
| 27 | + CloudColors_p, |
| 28 | + LavaColors_p, |
| 29 | + OceanColors_p, |
| 30 | + ForestColors_p, |
| 31 | + PartyColors_p, |
| 32 | + HeatColors_p |
| 33 | +}; |
| 34 | + |
| 35 | +const uint8_t paletteCount = ARRAY_SIZE(palettes); |
| 36 | + |
| 37 | +const String paletteNames[paletteCount] = { |
| 38 | + "Rainbow", |
| 39 | + "Rainbow Stripe", |
| 40 | + "Cloud", |
| 41 | + "Lava", |
| 42 | + "Ocean", |
| 43 | + "Forest", |
| 44 | + "Party", |
| 45 | + "Heat", |
| 46 | +}; |
| 47 | + |
| 48 | +void rainbow() |
| 49 | +{ |
| 50 | + // FastLED's built-in rainbow generator |
| 51 | + fill_rainbow( leds, NUM_LEDS, gHue, speed); |
| 52 | +} |
| 53 | + |
| 54 | +void addGlitter( fract8 chanceOfGlitter) |
| 55 | +{ |
| 56 | + if ( random8() < chanceOfGlitter) { |
| 57 | + leds[ random16(NUM_LEDS) ] += CRGB::White; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +void rainbowWithGlitter() |
| 62 | +{ |
| 63 | + // built-in FastLED rainbow, plus some random sparkly glitter |
| 64 | + rainbow(); |
| 65 | + addGlitter(80); |
| 66 | +} |
| 67 | + |
| 68 | +void confetti() |
| 69 | +{ |
| 70 | + // random colored speckles that blink in and fade smoothly |
| 71 | + fadeToBlackBy( leds, NUM_LEDS, 10); |
| 72 | + int pos = random16(NUM_LEDS); |
| 73 | + leds[pos] += CHSV( gHue + random8(64), 200, 255); |
| 74 | +} |
| 75 | + |
| 76 | +void sinelon() |
| 77 | +{ |
| 78 | + // a colored dot sweeping back and forth, with fading trails |
| 79 | + fadeToBlackBy( leds, NUM_LEDS, 20); |
| 80 | + int pos = beatsin16(speed, 0, NUM_LEDS - 1); |
| 81 | + static int prevpos = 0; |
| 82 | + CRGB color = ColorFromPalette(palettes[currentPaletteIndex], gHue, 255); |
| 83 | + if ( pos < prevpos ) { |
| 84 | + fill_solid( leds + pos, (prevpos - pos) + 1, color); |
| 85 | + } else { |
| 86 | + fill_solid( leds + prevpos, (pos - prevpos) + 1, color); |
| 87 | + } |
| 88 | + prevpos = pos; |
| 89 | +} |
| 90 | + |
| 91 | +void bpm() |
| 92 | +{ |
| 93 | + // colored stripes pulsing at a defined Beats-Per-Minute (BPM) |
| 94 | + uint8_t beat = beatsin8( speed, 64, 255); |
| 95 | + CRGBPalette16 palette = palettes[currentPaletteIndex]; |
| 96 | + for ( int i = 0; i < NUM_LEDS; i++) { |
| 97 | + leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10)); |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +void juggle() { |
| 102 | + // eight colored dots, weaving in and out of sync with each other |
| 103 | + fadeToBlackBy( leds, NUM_LEDS, 20); |
| 104 | + byte dothue = 0; |
| 105 | + for ( int i = 0; i < 8; i++) { |
| 106 | + leds[beatsin16( i + speed, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255); |
| 107 | + dothue += 32; |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +void showSolidColor() |
| 112 | +{ |
| 113 | + fill_solid(leds, NUM_LEDS, solidColor); |
| 114 | +} |
| 115 | + |
| 116 | +typedef void (*Pattern)(); |
| 117 | +typedef Pattern PatternList[]; |
| 118 | +typedef struct { |
| 119 | + Pattern pattern; |
| 120 | + String name; |
| 121 | +} PatternAndName; |
| 122 | +typedef PatternAndName PatternAndNameList[]; |
| 123 | + |
| 124 | +PatternAndNameList patterns = { |
| 125 | + { rainbow, "rainbow" }, |
| 126 | + { rainbowWithGlitter, "rainbowWithGlitter" }, |
| 127 | + { confetti, "confetti" }, |
| 128 | + { sinelon, "sinelon" }, |
| 129 | + { juggle, "juggle" }, |
| 130 | + { bpm, "bpm" }, |
| 131 | + |
| 132 | + { showSolidColor, "Solid Color" }, |
| 133 | +}; |
| 134 | + |
| 135 | +const uint8_t patternCount = ARRAY_SIZE(patterns); |
| 136 | + |
0 commit comments