|
| 1 | +// Selection of effects from the FastLED library & Macetech RGB Shades |
| 2 | + |
| 3 | + |
| 4 | +// Triple Sine Waves |
| 5 | +void threeSine() { |
| 6 | + |
| 7 | + static byte sineOffset = 0; // counter for current position of sine waves |
| 8 | + |
| 9 | + // startup tasks |
| 10 | + if (effectInit == false) { |
| 11 | + effectInit = true; |
| 12 | + effectDelay = 20; |
| 13 | + } |
| 14 | + |
| 15 | + // Draw one frame of the animation into the LED array |
| 16 | + for (byte x = 0; x < kMatrixWidth; x++) { |
| 17 | + for (int y = 0; y < kMatrixHeight; y++) { |
| 18 | + |
| 19 | + // Calculate "sine" waves with varying periods |
| 20 | + // sin8 is used for speed; cos8, quadwave8, or triwave8 would also work here |
| 21 | + byte sinDistanceR = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 9 + x * 16)), 2); |
| 22 | + byte sinDistanceG = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 10 + x * 16)), 2); |
| 23 | + byte sinDistanceB = qmul8(abs(y * (255 / kMatrixHeight) - sin8(sineOffset * 11 + x * 16)), 2); |
| 24 | + |
| 25 | + leds[XY(x, y)] = CRGB(255 - sinDistanceR, 255 - sinDistanceG, 255 - sinDistanceB); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + sineOffset++; // byte will wrap from 255 to 0, matching sin8 0-255 cycle |
| 30 | + |
| 31 | +} |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +// Solid Colors |
| 36 | +// Create your own! |
| 37 | +void SolidWhite() //for the porto-potty |
| 38 | +{ |
| 39 | + fill_solid( leds, NUM_LEDS, CRGB::White); |
| 40 | +} |
| 41 | + |
| 42 | +void SolidRed() //for startup, good for saving battery |
| 43 | +{ |
| 44 | + fill_solid( leds, NUM_LEDS, CRGB::Red); |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +// RGB Plasma |
| 50 | +void plasma() { |
| 51 | + |
| 52 | + static byte offset = 0; // counter for radial color wave motion |
| 53 | + static int plasVector = 0; // counter for orbiting plasma center |
| 54 | + |
| 55 | + // startup tasks |
| 56 | + if (effectInit == false) { |
| 57 | + effectInit = true; |
| 58 | + effectDelay = 10; |
| 59 | + } |
| 60 | + |
| 61 | + // Calculate current center of plasma pattern (can be offscreen) |
| 62 | + int xOffset = cos8(plasVector / 256); |
| 63 | + int yOffset = sin8(plasVector / 256); |
| 64 | + |
| 65 | + // Draw one frame of the animation into the LED array |
| 66 | + for (int x = 0; x < kMatrixWidth; x++) { |
| 67 | + for (int y = 0; y < kMatrixHeight; y++) { |
| 68 | + byte color = sin8(sqrt(sq(((float)x - 7.5) * 10 + xOffset - 127) + sq(((float)y - 2) * 10 + yOffset - 127)) + offset); |
| 69 | + leds[XY(x, y)] = CHSV(color, 255, 255); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + offset++; // wraps at 255 for sin8 |
| 74 | + plasVector += 16; // using an int for slower orbit (wraps at 65536) |
| 75 | + |
| 76 | +} |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +// Scanning pattern left/right, using global hue cycle |
| 81 | +void rider() { |
| 82 | + |
| 83 | + static byte riderPos = 0; |
| 84 | + |
| 85 | + // startup tasks |
| 86 | + if (effectInit == false) { |
| 87 | + effectInit = true; |
| 88 | + effectDelay = 5; |
| 89 | + riderPos = 0; |
| 90 | + } |
| 91 | + |
| 92 | + // Draw one frame of the animation into the LED array |
| 93 | + for (byte x = 0; x < kMatrixWidth; x++) { |
| 94 | + int brightness = abs(x * (256 / kMatrixWidth) - triwave8(riderPos) * 2 + 127) * 3; |
| 95 | + if (brightness > 255) brightness = 255; |
| 96 | + brightness = 255 - brightness; |
| 97 | + CRGB riderColor = CHSV(cycleHue, 255, brightness); |
| 98 | + for (byte y = 0; y < kMatrixHeight; y++) { |
| 99 | + leds[XY(x, y)] = riderColor; |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + riderPos++; // byte wraps to 0 at 255, triwave8 is also 0-255 periodic |
| 104 | + |
| 105 | +} |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | +// Fills saturated colors into the array from alternating directions |
| 110 | +void colorFill() { |
| 111 | + |
| 112 | + static byte currentColor = 0; |
| 113 | + static byte currentRow = 0; |
| 114 | + static byte currentDirection = 0; |
| 115 | + |
| 116 | + // startup tasks |
| 117 | + if (effectInit == false) { |
| 118 | + effectInit = true; |
| 119 | + effectDelay = 45; |
| 120 | + currentColor = 0; |
| 121 | + currentRow = 0; |
| 122 | + currentDirection = 0; |
| 123 | + currentPalette = RainbowColors_p; |
| 124 | + } |
| 125 | + |
| 126 | + // test a bitmask to fill up or down when currentDirection is 0 or 2 (0b00 or 0b10) |
| 127 | + if (!(currentDirection & 1)) { |
| 128 | + effectDelay = 45; // slower since vertical has fewer pixels |
| 129 | + for (byte x = 0; x < kMatrixWidth; x++) { |
| 130 | + byte y = currentRow; |
| 131 | + if (currentDirection == 2) y = kMatrixHeight - 1 - currentRow; |
| 132 | + leds[XY(x, y)] = currentPalette[currentColor]; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + // test a bitmask to fill left or right when currentDirection is 1 or 3 (0b01 or 0b11) |
| 137 | + if (currentDirection & 1) { |
| 138 | + effectDelay = 20; // faster since horizontal has more pixels |
| 139 | + for (byte y = 0; y < kMatrixHeight; y++) { |
| 140 | + byte x = currentRow; |
| 141 | + if (currentDirection == 3) x = kMatrixWidth - 1 - currentRow; |
| 142 | + leds[XY(x, y)] = currentPalette[currentColor]; |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + currentRow++; |
| 147 | + |
| 148 | + // detect when a fill is complete, change color and direction |
| 149 | + if ((!(currentDirection & 1) && currentRow >= kMatrixHeight) || ((currentDirection & 1) && currentRow >= kMatrixWidth)) { |
| 150 | + currentRow = 0; |
| 151 | + currentColor += random8(3, 6); |
| 152 | + if (currentColor > 15) currentColor -= 16; |
| 153 | + currentDirection++; |
| 154 | + if (currentDirection > 3) currentDirection = 0; |
| 155 | + effectDelay = 300; // wait a little bit longer after completing a fill |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | +// Random pixels scroll sideways, using current hue |
| 162 | +#define rainDir 0 |
| 163 | +void sideRain() { |
| 164 | + |
| 165 | + // startup tasks |
| 166 | + if (effectInit == false) { |
| 167 | + effectInit = true; |
| 168 | + effectDelay = 30; |
| 169 | + } |
| 170 | + |
| 171 | + scrollArray(rainDir); |
| 172 | + byte randPixel = random8(kMatrixHeight); |
| 173 | + for (byte y = 0; y < kMatrixHeight; y++) leds[XY((kMatrixWidth - 1) * rainDir, y)] = CRGB::Black; |
| 174 | + leds[XY((kMatrixWidth - 1)*rainDir, randPixel)] = CHSV(cycleHue, 255, 255); |
| 175 | + |
| 176 | +} |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | +// CONFETTI: pixels with random locations and random colors selected from a palette |
| 181 | +// Create your own confetti modes using the built in Palettes (see utils.h) or create your own |
| 182 | +// Use with the fadeAll function (see .ino) to allow old pixels to decay |
| 183 | +void confetti() { |
| 184 | + // startup tasks |
| 185 | + if (effectInit == false) { |
| 186 | + effectInit = true; |
| 187 | + effectDelay = 10; |
| 188 | + selectRandomPalette(); |
| 189 | + } |
| 190 | + |
| 191 | + // scatter random colored pixels at several random coordinates |
| 192 | + for (byte i = 0; i < 4; i++) { |
| 193 | + leds[XY(random16(kMatrixWidth), random16(kMatrixHeight))] = ColorFromPalette(currentPalette, random16(255), 255); //CHSV(random16(255), 255, 255); |
| 194 | + random16_add_entropy(1); |
| 195 | + } |
| 196 | +} |
| 197 | + |
| 198 | +//Palette for myConfetti |
| 199 | +const TProgmemPalette16 MyColors_p PROGMEM = |
| 200 | +{ |
| 201 | + CRGB:: Crimson, |
| 202 | + CRGB:: Maroon, |
| 203 | + CRGB:: Red, |
| 204 | + CRGB:: OrangeRed, |
| 205 | + |
| 206 | + CRGB:: Crimson, |
| 207 | + CRGB:: Maroon, |
| 208 | + CRGB:: Red, |
| 209 | + CRGB:: OrangeRed, |
| 210 | + |
| 211 | + CRGB:: Crimson, |
| 212 | + CRGB:: Maroon, |
| 213 | + CRGB:: Red, |
| 214 | + CRGB:: OrangeRed, |
| 215 | + |
| 216 | + CRGB:: Crimson, |
| 217 | + CRGB:: Maroon, |
| 218 | + CRGB:: Red, |
| 219 | + CRGB:: OrangeRed, |
| 220 | +}; |
| 221 | + |
| 222 | +void myConfetti() { |
| 223 | + // startup tasks |
| 224 | + if (effectInit == false) { |
| 225 | + effectInit = true; |
| 226 | + effectDelay = 15; |
| 227 | + } |
| 228 | + |
| 229 | + |
| 230 | +// scatter random colored pixels at several random coordinates |
| 231 | + for (byte i = 0; i < 4; i++) { |
| 232 | + leds[XY(random16(kMatrixWidth), random16(kMatrixHeight))] = ColorFromPalette(MyColors_p, random16(255), 255); //CHSV(random16(255), 255, 255); |
| 233 | + random16_add_entropy(1); |
| 234 | + } |
| 235 | + |
| 236 | +} |
| 237 | + |
| 238 | + |
| 239 | +// Example from the NoisePlusPalette FastLED example sketch. See utils.h |
| 240 | +void NoisePlusPalette() { |
| 241 | + |
| 242 | + fillnoise8(); |
| 243 | + |
| 244 | + mapNoiseToLEDsUsingPalette(); |
| 245 | + |
| 246 | +} |
| 247 | + |
| 248 | + |
| 249 | +// Draw slanting bars scrolling across the array, using current hue |
| 250 | +void slantBars() { |
| 251 | + |
| 252 | + static byte slantPos = 0; |
| 253 | + |
| 254 | + // startup tasks |
| 255 | + if (effectInit == false) { |
| 256 | + effectInit = true; |
| 257 | + effectDelay = 5; |
| 258 | + } |
| 259 | + |
| 260 | + for (byte x = 0; x < kMatrixWidth; x++) { |
| 261 | + for (byte y = 0; y < kMatrixHeight; y++) { |
| 262 | + leds[XY(x, y)] = CHSV(cycleHue, 255, quadwave8(x * 32 + y * 32 + slantPos)); |
| 263 | + } |
| 264 | + } |
| 265 | + |
| 266 | + slantPos -= 4; |
| 267 | + |
| 268 | +} |
| 269 | + |
| 270 | + |
| 271 | +//from Mark Kriegsman |
| 272 | +void swirly() |
| 273 | +{ |
| 274 | + // startup tasks |
| 275 | + if (effectInit == false) { |
| 276 | + effectInit = true; |
| 277 | + effectDelay = 15; |
| 278 | + } |
| 279 | + |
| 280 | + // Apply some blurring to whatever's already on the matrix |
| 281 | + // Note that we never actually clear the matrix, we just constantly |
| 282 | + // blur it repeatedly. Since the blurring is 'lossy', there's |
| 283 | + // an automatic trend toward black -- by design. |
| 284 | + uint8_t blurAmount = beatsin8(2,10,255); |
| 285 | + blur2d( leds, kMatrixWidth, kMatrixHeight, blurAmount); |
| 286 | + |
| 287 | + // Use two out-of-sync sine waves |
| 288 | + uint8_t i = beatsin8( 27, kBorderWidth, kMatrixHeight-kBorderWidth); |
| 289 | + uint8_t j = beatsin8( 41, kBorderWidth, kMatrixWidth-kBorderWidth); |
| 290 | + // Also calculate some reflections |
| 291 | + uint8_t ni = (kMatrixWidth-1)-i; |
| 292 | + uint8_t nj = (kMatrixWidth-1)-j; |
| 293 | + |
| 294 | + // The color of each point shifts over time, each at a different speed. |
| 295 | + uint16_t ms = millis(); |
| 296 | + leds[XY( i, j)] += CHSV( ms / 11, 200, 255); |
| 297 | + leds[XY( j, i)] += CHSV( ms / 13, 200, 255); |
| 298 | + leds[XY(ni,nj)] += CHSV( ms / 17, 200, 255); |
| 299 | + leds[XY(nj,ni)] += CHSV( ms / 29, 200, 255); |
| 300 | + leds[XY( i,nj)] += CHSV( ms / 37, 200, 255); |
| 301 | + leds[XY(ni, j)] += CHSV( ms / 41, 200, 255); |
| 302 | + |
| 303 | + FastLED.show(); |
| 304 | +} |
0 commit comments