├── src ├── NeoAnimationFX.cpp └── NeoAnimationFX.h ├── .travis.yml ├── library.properties ├── library.json ├── examples └── catalog_animations │ └── catalog_animations.ino ├── README.md ├── platformio.ini ├── keywords.txt └── LICENSE /src/NeoAnimationFX.cpp: -------------------------------------------------------------------------------- 1 | #include "NeoAnimationFX.h" 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "2.7" 4 | sudo: false 5 | cache: 6 | directories: 7 | - "~/.platformio" 8 | env: 9 | - PLATFORMIO_CI_SRC=examples/catalog_animations 10 | install: 11 | - pip install -U platformio 12 | - platformio update 13 | script: 14 | - platformio ci --project-conf=./platformio.ini -v -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=NeoAnimationFX 2 | version=0.3 3 | author=Debashish Sahu 4 | maintainer=Debashish Sahu 5 | sentence=A library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy. 6 | paragraph=Supports most Arduino platforms, including Esp8266 and Esp32. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang; and two methods of sending DotStar data, hardware SPI and software SPI. 7 | category=Display 8 | url=https://github.com/debsahu/NeoAnimationFX 9 | architectures=esp8266 10 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "NeoAnimationFX", 3 | "keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, RGB, RGBW", 4 | "description": "A animation library that makes controlling NeoPixels (WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102) easy. Supports most Arduino platforms. Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang; and two methods of sending DotStar data, hardware SPI and software SPI.", 5 | "homepage": "https://github.com/debsahu/NeoAnimationFX", 6 | "repository": 7 | { 8 | "type": "git", 9 | "url": "https://github.com/debsahu/NeoAnimationFX" 10 | }, 11 | "version": "0.3", 12 | "frameworks": "arduino", 13 | "platforms": "esp8266" 14 | } 15 | 16 | -------------------------------------------------------------------------------- /examples/catalog_animations/catalog_animations.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define numPixels 16 4 | #define PIN 2 //GPIO3 5 | 6 | #ifdef ESP8266 7 | typedef NeoPixelBrightnessBus NEOMETHOD; //uses GPIO3/RX 8 | //typedef NeoPixelBrightnessBus NEOMETHOD; //uses GPIO2/D4 9 | #endif 10 | #ifdef ESP32 11 | typedef NeoPixelBrightnessBus NEOMETHOD; 12 | #endif 13 | 14 | NEOMETHOD strip(numPixels, PIN); // PIN is ignored for ESP8266 15 | NeoAnimationFX myPixelRef(strip); 16 | 17 | int i=-1; 18 | long lastModeT = 0; 19 | bool MASTERMODE = false; 20 | int modetotry = FX_MODE_CUSTOM; 21 | 22 | void setup() { 23 | Serial.begin(115200); 24 | Serial.println(); 25 | myPixelRef.init(); 26 | myPixelRef.setColor(random(255),random(255),random(255)); 27 | // myPixelRef.setSpeed(65535); 28 | // myPixelRef.setBrightness(100); 29 | myPixelRef.start(); 30 | } 31 | 32 | void loop() { 33 | myPixelRef.service(); 34 | if (millis() - lastModeT > 5000) { 35 | lastModeT = millis(); 36 | myPixelRef.clear(); 37 | (MASTERMODE) ? i = modetotry : i++; 38 | if(i >= myPixelRef.getModeCount() ) i=0; 39 | myPixelRef.setMode(i); 40 | Serial.print("Mode: "); 41 | Serial.println(myPixelRef.getModeName(i)); 42 | } 43 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NeoAnimationFX 2 | This uses NeoPixelBrightnessBus and borrows code from awesome animations developed at [WS2812FX](https://github.com/kitesurfer1404/WS2812FX). 3 | 4 | ---------------------------------------- 5 | Check [WS2812FX example](https://github.com/kitesurfer1404/WS2812FX/blob/master/examples/ws2812fx_dma/ws2812fx_dma.ino), easier way to achieve this. Still want to use this, follow instructions below. 6 | ---------------------------------------- 7 | ## Why? 8 | - NeoPixelBrightnessBus uses DMA, so WiFi functions are not effected while animating. 9 | - Has support for numerous LED types 10 | - Very easy templates to handle RGB, HSL and HTML colors 11 | - Supports segments just like [WS2812FX](https://github.com/kitesurfer1404/WS2812FX) 12 | ## Limitations 13 | - RBGW leds not yet implemented! (not high priority) 14 | - Works on ESP8266 (for now), ESP32? 15 | - DMA method uses pin RX / GPIO3 16 | - UART method uses pin D4 / GPIO2 17 | - `Serial.begin();` needs to be started before `strip.Begin();` because both share the same pin. 18 | ## How to use the library 19 | * Download this GitHub [library](https://github.com/debsahu/NeoAnimationFX/archive/master.zip). 20 | * In Arduino, Goto Sketch -> Include Library -> Add .ZIP Library... and point to the zip file downloaded. 21 | * Install [NeoPixelBus library](https://github.com/Makuna/NeoPixelBus) using the same procedure. 22 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | [platformio] 2 | src_dir = ./examples/catalog_animations 3 | ;env_default = nodemcuv2 4 | 5 | [common] 6 | framework = arduino 7 | build_flags = 8 | -w 9 | -D PIO_PLATFORM 10 | lib_deps = 11 | NeoPixelBus 12 | NeoAnimationFX=https://github.com/debsahu/NeoAnimationFX 13 | monitor_speed = 115200 14 | upload_speed = 115200 15 | upload_speed_fast = 921600 16 | targets_eum = erase, upload, monitor 17 | targets_um = upload, monitor 18 | 19 | # see: http://docs.platformio.org/en/latest/platforms/espressif32.html 20 | [common:esp32] 21 | framework = ${common.framework} 22 | platform = espressif32@1.6.0 23 | ;platform = https://github.com/platformio/platform-espressif32.git#feature/stage 24 | build_flags = 25 | ${common.build_flags} 26 | -D ARDUINO_ARCH_ESP32 27 | monitor_speed = ${common.monitor_speed} 28 | upload_speed = ${common.upload_speed} 29 | upload_speed_fast = ${common.upload_speed_fast} 30 | lib_deps = 31 | ${common.lib_deps} 32 | lib_ignore = 33 | none 34 | 35 | # see: http://docs.platformio.org/en/latest/platforms/espressif8266.html 36 | [common:esp8266] 37 | framework = ${common.framework} 38 | platform = espressif8266@1.8.0 39 | ;platform = https://github.com/platformio/platform-espressif8266.git#feature/stage 40 | monitor_speed = ${common.monitor_speed} 41 | board_build.flash_mode = dio 42 | upload_speed = ${common.upload_speed} 43 | upload_speed_fast = ${common.upload_speed_fast} 44 | upload_resetmethod = nodemcu 45 | build_flags = 46 | ${common.build_flags} 47 | -Teagle.flash.4m3m.ld 48 | lib_deps = 49 | ${common.lib_deps} 50 | lib_ignore = 51 | none 52 | 53 | [env:nodemcuv2] 54 | board = nodemcuv2 55 | framework = ${common:esp8266.framework} 56 | platform = ${common:esp8266.platform} 57 | build_flags = ${common:esp8266.build_flags} 58 | board_build.flash_mode = ${common:esp8266.board_build.flash_mode} 59 | monitor_speed = ${common:esp8266.monitor_speed} 60 | upload_speed = ${common:esp8266.upload_speed} 61 | upload_resetmethod = ${common:esp8266.upload_resetmethod} 62 | lib_deps = ${common:esp8266.lib_deps} 63 | ;targets = ${common.targets_um} 64 | 65 | [env:esp32dev] 66 | board = esp32dev 67 | framework = ${common.framework} 68 | platform = ${common:esp32.platform} 69 | monitor_speed = ${common:esp32.monitor_speed} 70 | upload_speed = ${common:esp32.upload_speed_fast} 71 | build_flags = ${common:esp32.build_flags} 72 | lib_deps = ${common:esp32.lib_deps} 73 | lib_ignore = ${common:esp32.lib_ignore} 74 | ;targets = ${common.targets_um} -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map NeoPixelBus 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | NeoAnimationFX KEYWORD1 10 | NeoPBBGRB800 KEYWORD1 11 | NeoPBBGRB400 KEYWORD1 12 | NeoPBBGRBU800 KEYWORD1 13 | NeoPBBGRBU400 KEYWORD1 14 | NeoPBBGRBD800 KEYWORD1 15 | NeoPBBGRBD400 KEYWORD1 16 | NeoPBBGRBBB800 KEYWORD1 17 | NeoPBBGRBBB400 KEYWORD1 18 | NeoPBBRGB800 KEYWORD1 19 | NeoPBBRGB400 KEYWORD1 20 | NeoPBBRGBU800 KEYWORD1 21 | NeoPBBRGBU400 KEYWORD1 22 | NeoPBBRGBD800 KEYWORD1 23 | NeoPBBRGBD400 KEYWORD1 24 | NeoPBBRGBBB800 KEYWORD1 25 | NeoPBBRGBBB400 KEYWORD1 26 | NeoPixelBus KEYWORD1 27 | RgbwColor KEYWORD1 28 | RgbColor KEYWORD1 29 | HslColor KEYWORD1 30 | HsbColor KEYWORD1 31 | HtmlColor KEYWORD1 32 | NeoGrbFeature KEYWORD1 33 | NeoGrbwFeature KEYWORD1 34 | NeoRgbwFeature KEYWORD1 35 | NeoRgbFeature KEYWORD1 36 | NeoBrgFeature KEYWORD1 37 | NeoRbgFeature KEYWORD1 38 | DotStarBgrFeature KEYWORD1 39 | DotStarLbgrFeature KEYWORD1 40 | NeoWs2813Method KEYWORD1 41 | Neo800KbpsMethod KEYWORD1 42 | Neo400KbpsMethod KEYWORD1 43 | NeoAvrWs2813Method KEYWORD1 44 | NeoAvr800KbpsMethod KEYWORD1 45 | NeoAvr400KbpsMethod KEYWORD1 46 | NeoEsp8266DmaWs2813Method KEYWORD1 47 | NeoEsp8266Dma800KbpsMethod KEYWORD1 48 | NeoEsp8266Dma400KbpsMethod KEYWORD1 49 | NeoEsp8266UartWs2813Method KEYWORD1 50 | NeoEsp8266Uart800KbpsMethod KEYWORD1 51 | NeoEsp8266Uart400KbpsMethod KEYWORD1 52 | NeoEsp8266AsyncUartWs2813Method KEYWORD1 53 | NeoEsp8266AsyncUart800KbpsMethod KEYWORD1 54 | NeoEsp8266AsyncUart400KbpsMethod KEYWORD1 55 | NeoEsp8266BitBangWs2813Method KEYWORD1 56 | NeoEsp8266BitBang800KbpsMethod KEYWORD1 57 | NeoEsp8266BitBang400KbpsMethod KEYWORD1 58 | NeoEsp32BitBangWs2813Method KEYWORD1 59 | NeoEsp32BitBang800KbpsMethod KEYWORD1 60 | NeoEsp32BitBang400KbpsMethod KEYWORD1 61 | DotStarMethod KEYWORD1 62 | DotStarSpiMethod KEYWORD1 63 | NeoPixelAnimator KEYWORD1 64 | AnimUpdateCallback KEYWORD1 65 | AnimationParam KEYWORD1 66 | NeoEase KEYWORD1 67 | AnimEaseFunction KEYWORD1 68 | RowMajorLayout KEYWORD1 69 | RowMajor90Layout KEYWORD1 70 | RowMajor180Layout KEYWORD1 71 | RowMajor270Layout KEYWORD1 72 | RowMajorAlternatingLayout KEYWORD1 73 | RowMajorAlternating90Layout KEYWORD1 74 | RowMajorAlternating180Layout KEYWORD1 75 | RowMajorAlternating270Layout KEYWORD1 76 | ColumnMajorLayout KEYWORD1 77 | ColumnMajor90Layout KEYWORD1 78 | ColumnMajor180Layout KEYWORD1 79 | ColumnMajor270Layout KEYWORD1 80 | ColumnMajorAlternatingLayout KEYWORD1 81 | ColumnMajorAlternating90Layout KEYWORD1 82 | ColumnMajorAlternating180Layout KEYWORD1 83 | ColumnMajorAlternating270Layout KEYWORD1 84 | NeoTopology KEYWORD1 85 | NeoRingTopology KEYWORD1 86 | NeoTiles KEYWORD1 87 | NeoMosaic KEYWORD1 88 | NeoGammaEquationMethod KEYWORD1 89 | NeoGammaTableMethod KEYWORD1 90 | NeoGamma KEYWORD1 91 | NeoHueBlendShortestDistance KEYWORD1 92 | NeoHueBlendLongestDistance KEYWORD1 93 | NeoHueBlendClockwiseDirection KEYWORD1 94 | NeoHueBlendCounterClockwiseDirection KEYWORD1 95 | NeoBufferContext KEYWORD1 96 | LayoutMapCallback KEYWORD1 97 | NeoBufferMethod KEYWORD1 98 | NeoBufferProgmemMethod KEYWORD1 99 | NeoBuffer KEYWORD1 100 | NeoVerticalSpriteSheet KEYWORD1 101 | NeoBitmapFile KEYWORD1 102 | HtmlShortColorNames KEYWORD1 103 | HtmlColorNames KEYWORD1 104 | 105 | ####################################### 106 | # Methods and Functions (KEYWORD2) 107 | ####################################### 108 | 109 | Begin KEYWORD2 110 | Show KEYWORD2 111 | CanShow KEYWORD2 112 | ClearTo KEYWORD2 113 | RotateLeft KEYWORD2 114 | ShiftLeft KEYWORD2 115 | RotateRight KEYWORD2 116 | ShiftRight KEYWORD2 117 | IsDirty KEYWORD2 118 | Dirty KEYWORD2 119 | ResetDirty KEYWORD2 120 | Pixels KEYWORD2 121 | PixelsSize KEYWORD2 122 | PixelCount KEYWORD2 123 | SetPixelColor KEYWORD2 124 | GetPixelColor KEYWORD2 125 | CalculateBrightness KEYWORD2 126 | Darken KEYWORD2 127 | Lighten KEYWORD2 128 | LinearBlend KEYWORD2 129 | BilinearBlend KEYWORD2 130 | IsAnimating KEYWORD2 131 | NextAvailableAnimation KEYWORD2 132 | StartAnimation KEYWORD2 133 | StopAnimation KEYWORD2 134 | RestartAnimation KEYWORD2 135 | IsAnimationActive KEYWORD2 136 | AnimationDuration KEYWORD2 137 | UpdateAnimations KEYWORD2 138 | IsPaused KEYWORD2 139 | Pause KEYWORD2 140 | Resume KEYWORD2 141 | getTimeScale KEYWORD2 142 | setTimeScale KEYWORD2 143 | QuadraticIn KEYWORD2 144 | QuadraticOut KEYWORD2 145 | QuadraticInOut KEYWORD2 146 | CubicIn KEYWORD2 147 | CubicOut KEYWORD2 148 | CubicInOut KEYWORD2 149 | QuarticIn KEYWORD2 150 | QuarticOut KEYWORD2 151 | QuarticInOut KEYWORD2 152 | QuinticIn KEYWORD2 153 | QuinticOut KEYWORD2 154 | QuinticInOut KEYWORD2 155 | SinusoidalIn KEYWORD2 156 | SinusoidalOut KEYWORD2 157 | SinusoidalInOut KEYWORD2 158 | ExponentialIn KEYWORD2 159 | ExponentialOut KEYWORD2 160 | ExponentialInOut KEYWORD2 161 | CircularIn KEYWORD2 162 | CircularOut KEYWORD2 163 | CircularInOut KEYWORD2 164 | Gamma KEYWORD2 165 | Map KEYWORD2 166 | MapProbe KEYWORD2 167 | getWidth KEYWORD2 168 | getHeight KEYWORD2 169 | getCountOfRings KEYWORD2 170 | getPixelCountAtRing KEYWORD2 171 | getPixelCount KEYWORD2 172 | TopologyHint KEYWORD2 173 | Correct KEYWORD2 174 | SpriteWidth KEYWORD2 175 | SpriteHeight KEYWORD2 176 | SpriteCount KEYWORD2 177 | Blt KEYWORD2 178 | Width KEYWORD2 179 | Height KEYWORD2 180 | Parse KEYWORD2 181 | ToString KEYWORD2 182 | ToNumericalString KEYWORD2 183 | init KEYWORD2 184 | service KEYWORD2 185 | start KEYWORD2 186 | stop KEYWORD2 187 | reverse KEYWORD2 188 | trigger KEYWORD2 189 | setMode KEYWORD2 190 | setCustomMode KEYWORD2 191 | setSpeed KEYWORD2 192 | increaseSpeed KEYWORD2 193 | decreaseSpeed KEYWORD2 194 | setColor KEYWORD2 195 | setBrightness KEYWORD2 196 | setLength KEYWORD2 197 | getLength KEYWORD2 198 | setSegment KEYWORD2 199 | resetSegments KEYWORD2 200 | increaseBrightness KEYWORD2 201 | decreaseBrightness KEYWORD2 202 | increaseLength KEYWORD2 203 | decreaseLength KEYWORD2 204 | isRunning KEYWORD2 205 | getMode KEYWORD2 206 | getSpeed KEYWORD2 207 | getBrightness KEYWORD2 208 | getModeCount KEYWORD2 209 | getModeName KEYWORD2 210 | getColor KEYWORD2 211 | getNumSegments KEYWORD2 212 | setNumSegments KEYWORD2 213 | getSegments KEYWORD2 214 | color_wheel KEYWORD2 215 | FX_MODE_STATIC KEYWORD2 216 | FX_MODE_BLINK KEYWORD2 217 | FX_MODE_BREATH KEYWORD2 218 | FX_MODE_COLOR_WIPE KEYWORD2 219 | FX_MODE_COLOR_WIPE_INV KEYWORD2 220 | FX_MODE_COLOR_WIPE_REV KEYWORD2 221 | FX_MODE_COLOR_WIPE_REV_INV KEYWORD2 222 | FX_MODE_COLOR_WIPE_RANDOM KEYWORD2 223 | FX_MODE_RANDOM_COLOR KEYWORD2 224 | FX_MODE_SINGLE_DYNAMIC KEYWORD2 225 | FX_MODE_MULTI_DYNAMIC KEYWORD2 226 | FX_MODE_RAINBOW KEYWORD2 227 | FX_MODE_RAINBOW_CYCLE KEYWORD2 228 | FX_MODE_SCAN KEYWORD2 229 | FX_MODE_DUAL_SCAN KEYWORD2 230 | FX_MODE_FADE KEYWORD2 231 | FX_MODE_THEATER_CHASE KEYWORD2 232 | FX_MODE_THEATER_CHASE_RAINBOW KEYWORD2 233 | FX_MODE_RUNNING_LIGHTS KEYWORD2 234 | FX_MODE_TWINKLE KEYWORD2 235 | FX_MODE_TWINKLE_RANDOM KEYWORD2 236 | FX_MODE_TWINKLE_FADE KEYWORD2 237 | FX_MODE_TWINKLE_FADE_RANDOM KEYWORD2 238 | FX_MODE_SPARKLE KEYWORD2 239 | FX_MODE_FLASH_SPARKLE KEYWORD2 240 | FX_MODE_HYPER_SPARKLE KEYWORD2 241 | FX_MODE_STROBE KEYWORD2 242 | FX_MODE_STROBE_RAINBOW KEYWORD2 243 | FX_MODE_MULTI_STROBE KEYWORD2 244 | FX_MODE_BLINK_RAINBOW KEYWORD2 245 | FX_MODE_CHASE_WHITE KEYWORD2 246 | FX_MODE_CHASE_COLOR KEYWORD2 247 | FX_MODE_CHASE_RANDOM KEYWORD2 248 | FX_MODE_CHASE_RAINBOW KEYWORD2 249 | FX_MODE_CHASE_FLASH KEYWORD2 250 | FX_MODE_CHASE_FLASH_RANDOM KEYWORD2 251 | FX_MODE_CHASE_RAINBOW_WHITE KEYWORD2 252 | FX_MODE_CHASE_BLACKOUT KEYWORD2 253 | FX_MODE_CHASE_BLACKOUT_RAINBOW KEYWORD2 254 | FX_MODE_COLOR_SWEEP_RANDOM KEYWORD2 255 | FX_MODE_RUNNING_COLOR KEYWORD2 256 | FX_MODE_RUNNING_RED_BLUE KEYWORD2 257 | FX_MODE_RUNNING_RANDOM KEYWORD2 258 | FX_MODE_LARSON_SCANNER KEYWORD2 259 | FX_MODE_COMET KEYWORD2 260 | FX_MODE_FIREWORKS KEYWORD2 261 | FX_MODE_FIREWORKS_RANDOM KEYWORD2 262 | FX_MODE_MERRY_CHRISTMAS KEYWORD2 263 | FX_MODE_HALLOWEEN KEYWORD2 264 | FX_MODE_FIRE_FLICKER KEYWORD2 265 | FX_MODE_FIRE_FLICKER_SOFT KEYWORD2 266 | FX_MODE_FIRE_FLICKER_INTENSE KEYWORD2 267 | FX_MODE_DUAL_COLOR_WIPE_IN_OUT KEYWORD2 268 | FX_MODE_DUAL_COLOR_WIPE_IN_IN KEYWORD2 269 | FX_MODE_DUAL_COLOR_WIPE_OUT_OUT KEYWORD2 270 | FX_MODE_DUAL_COLOR_WIPE_OUT_IN KEYWORD2 271 | FX_MODE_CIRCUS_COMBUSTUS KEYWORD2 272 | FX_MODE_BICOLOR_CHASE KEYWORD2 273 | FX_MODE_TRICOLOR_CHASE KEYWORD2 274 | FX_MODE_ICU KEYWORD2 275 | FX_MODE_METEOR_RAIN KEYWORD2 276 | 277 | ####################################### 278 | # Constants (LITERAL1) 279 | ####################################### 280 | 281 | NEO_MILLISECONDS LITERAL1 282 | NEO_CENTISECONDS LITERAL1 283 | NEO_DECISECONDS LITERAL1 284 | NEO_SECONDS LITERAL1 285 | NEO_DECASECONDS LITERAL1 286 | AnimationState_Started LITERAL1 287 | AnimationState_Progress LITERAL1 288 | AnimationState_Completed LITERAL1 289 | NeoTopologyHint_FirstOnPanel LITERAL1 290 | NeoTopologyHint_InPanel LITERAL1 291 | NeoTopologyHint_LastOnPanel LITERAL1 292 | NeoTopologyHint_OutOfBounds LITERAL1 293 | PixelIndex_OutOfBounds LITERAL1 294 | ORANGE LITERAL1 295 | PURPLE LITERAL1 296 | MAGENTA LITERAL1 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /src/NeoAnimationFX.h: -------------------------------------------------------------------------------- 1 | #ifndef NeoAnimationFX_h 2 | #define NeoAnimationFX_h 3 | 4 | #include 5 | 6 | #define DEFAULT_BRIGHTNESS 50 7 | #define DEFAULT_MODE 0 8 | #define DEFAULT_SPEED 1000 9 | #define DEFAULT_COLOR 0xFF0000 10 | 11 | #define SPEED_MIN 10 12 | #define SPEED_MAX 65535 13 | 14 | #define BRIGHTNESS_MIN 0 15 | #define BRIGHTNESS_MAX 255 16 | 17 | /* each segment uses 34 bytes of SRAM memory, so if you're application fails because of 18 | insufficient memory, decreasing MAX_NUM_SEGMENTS may help */ 19 | #define MAX_NUM_SEGMENTS 10 20 | #define NUM_COLORS 3 /* number of colors per segment */ 21 | #define SEGMENT _segments[_segment_index] 22 | #define SEGMENT_RUNTIME _segment_runtimes[_segment_index] 23 | #define SEGMENT_LENGTH (SEGMENT.stop - SEGMENT.start + 1) 24 | #define RESET_RUNTIME memset(_segment_runtimes, 0, sizeof(_segment_runtimes)) 25 | 26 | // some common colors 27 | #define RED 0xFF0000 28 | #define GREEN 0x00FF00 29 | #define BLUE 0x0000FF 30 | #define WHITE 0xFFFFFF 31 | #define BLACK 0x000000 32 | #define YELLOW 0xFFFF00 33 | #define CYAN 0x00FFFF 34 | #define MAGENTA 0xFF00FF 35 | #define PURPLE 0x400080 36 | #define ORANGE 0xFF3000 37 | #define ULTRAWHITE 0xFFFFFFFF 38 | 39 | #define MODE_COUNT 58 40 | 41 | #define FX_MODE_STATIC 0 42 | #define FX_MODE_BLINK 1 43 | #define FX_MODE_BREATH 2 44 | #define FX_MODE_COLOR_WIPE 3 45 | #define FX_MODE_COLOR_WIPE_INV 4 46 | #define FX_MODE_COLOR_WIPE_REV 5 47 | #define FX_MODE_COLOR_WIPE_REV_INV 6 48 | #define FX_MODE_COLOR_WIPE_RANDOM 7 49 | #define FX_MODE_RANDOM_COLOR 8 50 | #define FX_MODE_SINGLE_DYNAMIC 9 51 | #define FX_MODE_MULTI_DYNAMIC 10 52 | #define FX_MODE_RAINBOW 11 53 | #define FX_MODE_RAINBOW_CYCLE 12 54 | #define FX_MODE_SCAN 13 55 | #define FX_MODE_DUAL_SCAN 14 56 | #define FX_MODE_FADE 15 57 | #define FX_MODE_THEATER_CHASE 16 58 | #define FX_MODE_THEATER_CHASE_RAINBOW 17 59 | #define FX_MODE_RUNNING_LIGHTS 18 60 | #define FX_MODE_TWINKLE 19 61 | #define FX_MODE_TWINKLE_RANDOM 20 62 | #define FX_MODE_TWINKLE_FADE 21 63 | #define FX_MODE_TWINKLE_FADE_RANDOM 22 64 | #define FX_MODE_SPARKLE 23 65 | #define FX_MODE_FLASH_SPARKLE 24 66 | #define FX_MODE_HYPER_SPARKLE 25 67 | #define FX_MODE_STROBE 26 68 | #define FX_MODE_STROBE_RAINBOW 27 69 | #define FX_MODE_MULTI_STROBE 28 70 | #define FX_MODE_BLINK_RAINBOW 29 71 | #define FX_MODE_CHASE_WHITE 30 72 | #define FX_MODE_CHASE_COLOR 31 73 | #define FX_MODE_CHASE_RANDOM 32 74 | #define FX_MODE_CHASE_RAINBOW 33 75 | #define FX_MODE_CHASE_FLASH 34 76 | #define FX_MODE_CHASE_FLASH_RANDOM 35 77 | #define FX_MODE_CHASE_RAINBOW_WHITE 36 78 | #define FX_MODE_CHASE_BLACKOUT 37 79 | #define FX_MODE_CHASE_BLACKOUT_RAINBOW 38 80 | #define FX_MODE_COLOR_SWEEP_RANDOM 39 81 | #define FX_MODE_RUNNING_COLOR 40 82 | #define FX_MODE_RUNNING_RED_BLUE 41 83 | #define FX_MODE_RUNNING_RANDOM 42 84 | #define FX_MODE_LARSON_SCANNER 43 85 | #define FX_MODE_COMET 44 86 | #define FX_MODE_FIREWORKS 45 87 | #define FX_MODE_FIREWORKS_RANDOM 46 88 | #define FX_MODE_MERRY_CHRISTMAS 47 89 | #define FX_MODE_FIRE_FLICKER 48 90 | #define FX_MODE_FIRE_FLICKER_SOFT 49 91 | #define FX_MODE_FIRE_FLICKER_INTENSE 50 92 | #define FX_MODE_CIRCUS_COMBUSTUS 51 93 | #define FX_MODE_HALLOWEEN 52 94 | #define FX_MODE_BICOLOR_CHASE 53 95 | #define FX_MODE_TRICOLOR_CHASE 54 96 | #define FX_MODE_ICU 55 97 | #define FX_MODE_CUSTOM 56 98 | #define FX_MODE_METEOR_RAIN 57 99 | 100 | #define MAX_PIXEL_CT 3000 101 | 102 | template class NeoAnimationFX { 103 | typedef uint16_t (NeoAnimationFX::*mode_ptr)(void); 104 | 105 | public: 106 | 107 | // segment parameters 108 | 109 | /* set default values c way 110 | struct segment_struct { 111 | uint8_t mode; 112 | RgbColor color; 113 | uint16_t speed; 114 | uint16_t start; 115 | uint16_t stop; 116 | bool reverse; 117 | } segment_default = { FX_MODE_STATIC, (RgbColor) HtmlColor(DEFAULT_COLOR), DEFAULT_SPEED, 0, 7, false}; 118 | 119 | typedef struct segment_struct segment; */ 120 | 121 | typedef struct Segment { 122 | uint8_t mode; 123 | RgbColor colors[NUM_COLORS]; 124 | uint16_t speed; 125 | uint16_t start; 126 | uint16_t stop; 127 | bool reverse; 128 | // set default values c++ way 129 | Segment(): 130 | mode(FX_MODE_STATIC), 131 | colors({(RgbColor) HtmlColor(DEFAULT_COLOR), (RgbColor) HtmlColor(BLACK), (RgbColor) HtmlColor(GREEN)}), 132 | speed(DEFAULT_SPEED), 133 | start(0), 134 | stop(7), 135 | reverse(false) {} 136 | } segment; 137 | 138 | // segment runtime parameters 139 | typedef struct Segment_runtime { 140 | uint32_t counter_mode_step; 141 | uint32_t counter_mode_call; 142 | unsigned long next_time; 143 | uint16_t aux_param; 144 | } segment_runtime; 145 | 146 | NeoAnimationFX(T_PIXEL_METHOD& pixelStrip) : 147 | _strip(pixelStrip) { 148 | _mode[FX_MODE_STATIC] = &NeoAnimationFX::mode_static; 149 | _mode[FX_MODE_BLINK] = &NeoAnimationFX::mode_blink; 150 | _mode[FX_MODE_COLOR_WIPE] = &NeoAnimationFX::mode_color_wipe; 151 | _mode[FX_MODE_COLOR_WIPE_INV] = &NeoAnimationFX::mode_color_wipe_inv; 152 | _mode[FX_MODE_COLOR_WIPE_REV] = &NeoAnimationFX::mode_color_wipe_rev; 153 | _mode[FX_MODE_COLOR_WIPE_REV_INV] = &NeoAnimationFX::mode_color_wipe_rev_inv; 154 | _mode[FX_MODE_COLOR_WIPE_RANDOM] = &NeoAnimationFX::mode_color_wipe_random; 155 | _mode[FX_MODE_RANDOM_COLOR] = &NeoAnimationFX::mode_random_color; 156 | _mode[FX_MODE_SINGLE_DYNAMIC] = &NeoAnimationFX::mode_single_dynamic; 157 | _mode[FX_MODE_MULTI_DYNAMIC] = &NeoAnimationFX::mode_multi_dynamic; 158 | _mode[FX_MODE_RAINBOW] = &NeoAnimationFX::mode_rainbow; 159 | _mode[FX_MODE_RAINBOW_CYCLE] = &NeoAnimationFX::mode_rainbow_cycle; 160 | _mode[FX_MODE_SCAN] = &NeoAnimationFX::mode_scan; 161 | _mode[FX_MODE_DUAL_SCAN] = &NeoAnimationFX::mode_dual_scan; 162 | _mode[FX_MODE_FADE] = &NeoAnimationFX::mode_fade; 163 | _mode[FX_MODE_THEATER_CHASE] = &NeoAnimationFX::mode_theater_chase; 164 | _mode[FX_MODE_THEATER_CHASE_RAINBOW] = &NeoAnimationFX::mode_theater_chase_rainbow; 165 | _mode[FX_MODE_TWINKLE] = &NeoAnimationFX::mode_twinkle; 166 | _mode[FX_MODE_TWINKLE_RANDOM] = &NeoAnimationFX::mode_twinkle_random; 167 | _mode[FX_MODE_TWINKLE_FADE] = &NeoAnimationFX::mode_twinkle_fade; 168 | _mode[FX_MODE_TWINKLE_FADE_RANDOM] = &NeoAnimationFX::mode_twinkle_fade_random; 169 | _mode[FX_MODE_SPARKLE] = &NeoAnimationFX::mode_sparkle; 170 | _mode[FX_MODE_FLASH_SPARKLE] = &NeoAnimationFX::mode_flash_sparkle; 171 | _mode[FX_MODE_HYPER_SPARKLE] = &NeoAnimationFX::mode_hyper_sparkle; 172 | _mode[FX_MODE_STROBE] = &NeoAnimationFX::mode_strobe; 173 | _mode[FX_MODE_STROBE_RAINBOW] = &NeoAnimationFX::mode_strobe_rainbow; 174 | _mode[FX_MODE_MULTI_STROBE] = &NeoAnimationFX::mode_multi_strobe; 175 | _mode[FX_MODE_BLINK_RAINBOW] = &NeoAnimationFX::mode_blink_rainbow; 176 | _mode[FX_MODE_CHASE_WHITE] = &NeoAnimationFX::mode_chase_white; 177 | _mode[FX_MODE_CHASE_COLOR] = &NeoAnimationFX::mode_chase_color; 178 | _mode[FX_MODE_CHASE_RANDOM] = &NeoAnimationFX::mode_chase_random; 179 | _mode[FX_MODE_CHASE_RAINBOW] = &NeoAnimationFX::mode_chase_rainbow; 180 | _mode[FX_MODE_CHASE_FLASH] = &NeoAnimationFX::mode_chase_flash; 181 | _mode[FX_MODE_CHASE_FLASH_RANDOM] = &NeoAnimationFX::mode_chase_flash_random; 182 | _mode[FX_MODE_CHASE_RAINBOW_WHITE] = &NeoAnimationFX::mode_chase_rainbow_white; 183 | _mode[FX_MODE_CHASE_BLACKOUT] = &NeoAnimationFX::mode_chase_blackout; 184 | _mode[FX_MODE_CHASE_BLACKOUT_RAINBOW] = &NeoAnimationFX::mode_chase_blackout_rainbow; 185 | _mode[FX_MODE_COLOR_SWEEP_RANDOM] = &NeoAnimationFX::mode_color_sweep_random; 186 | _mode[FX_MODE_RUNNING_COLOR] = &NeoAnimationFX::mode_running_color; 187 | _mode[FX_MODE_RUNNING_RED_BLUE] = &NeoAnimationFX::mode_running_red_blue; 188 | _mode[FX_MODE_RUNNING_RANDOM] = &NeoAnimationFX::mode_running_random; 189 | _mode[FX_MODE_LARSON_SCANNER] = &NeoAnimationFX::mode_larson_scanner; 190 | _mode[FX_MODE_COMET] = &NeoAnimationFX::mode_comet; 191 | _mode[FX_MODE_FIREWORKS] = &NeoAnimationFX::mode_fireworks; 192 | _mode[FX_MODE_FIREWORKS_RANDOM] = &NeoAnimationFX::mode_fireworks_random; 193 | _mode[FX_MODE_MERRY_CHRISTMAS] = &NeoAnimationFX::mode_merry_christmas; 194 | _mode[FX_MODE_HALLOWEEN] = &NeoAnimationFX::mode_halloween; 195 | _mode[FX_MODE_FIRE_FLICKER] = &NeoAnimationFX::mode_fire_flicker; 196 | _mode[FX_MODE_FIRE_FLICKER_SOFT] = &NeoAnimationFX::mode_fire_flicker_soft; 197 | _mode[FX_MODE_FIRE_FLICKER_INTENSE] = &NeoAnimationFX::mode_fire_flicker_intense; 198 | _mode[FX_MODE_CIRCUS_COMBUSTUS] = &NeoAnimationFX::mode_circus_combustus; 199 | _mode[FX_MODE_BICOLOR_CHASE] = &NeoAnimationFX::mode_bicolor_chase; 200 | _mode[FX_MODE_TRICOLOR_CHASE] = &NeoAnimationFX::mode_tricolor_chase; 201 | // if flash memory is constrained (I'm looking at you Arduino Nano), replace modes 202 | // that use a lot of flash with mode_static (reduces flash footprint by about 3600 bytes) 203 | #ifdef REDUCED_MODES 204 | _mode[FX_MODE_BREATH] = &NeoAnimationFX::mode_static; 205 | _mode[FX_MODE_RUNNING_LIGHTS] = &NeoAnimationFX::mode_static; 206 | _mode[FX_MODE_ICU] = &NeoAnimationFX::mode_static; 207 | #else 208 | _mode[FX_MODE_BREATH] = &NeoAnimationFX::mode_breath; 209 | _mode[FX_MODE_RUNNING_LIGHTS] = &NeoAnimationFX::mode_running_lights; 210 | _mode[FX_MODE_ICU] = &NeoAnimationFX::mode_icu; 211 | #endif 212 | _mode[FX_MODE_CUSTOM] = &NeoAnimationFX::mode_custom; 213 | _mode[FX_MODE_METEOR_RAIN] = &NeoAnimationFX::mode_meteor_rain; 214 | 215 | _name[FX_MODE_STATIC] = F("Static"); 216 | _name[FX_MODE_BLINK] = F("Blink"); 217 | _name[FX_MODE_BREATH] = F("Breath"); 218 | _name[FX_MODE_COLOR_WIPE] = F("Color Wipe"); 219 | _name[FX_MODE_COLOR_WIPE_INV ] = F("Color Wipe Inverse"); 220 | _name[FX_MODE_COLOR_WIPE_REV] = F("Color Wipe Reverse"); 221 | _name[FX_MODE_COLOR_WIPE_REV_INV] = F("Color Wipe Reverse Inverse"); 222 | _name[FX_MODE_COLOR_WIPE_RANDOM] = F("Color Wipe Random"); 223 | _name[FX_MODE_RANDOM_COLOR] = F("Random Color"); 224 | _name[FX_MODE_SINGLE_DYNAMIC] = F("Single Dynamic"); 225 | _name[FX_MODE_MULTI_DYNAMIC] = F("Multi Dynamic"); 226 | _name[FX_MODE_RAINBOW] = F("Rainbow"); 227 | _name[FX_MODE_RAINBOW_CYCLE] = F("Rainbow Cycle"); 228 | _name[FX_MODE_SCAN] = F("Scan"); 229 | _name[FX_MODE_DUAL_SCAN] = F("Dual Scan"); 230 | _name[FX_MODE_FADE] = F("Fade"); 231 | _name[FX_MODE_THEATER_CHASE] = F("Theater Chase"); 232 | _name[FX_MODE_THEATER_CHASE_RAINBOW] = F("Theater Chase Rainbow"); 233 | _name[FX_MODE_RUNNING_LIGHTS] = F("Running Lights"); 234 | _name[FX_MODE_TWINKLE] = F("Twinkle"); 235 | _name[FX_MODE_TWINKLE_RANDOM] = F("Twinkle Random"); 236 | _name[FX_MODE_TWINKLE_FADE] = F("Twinkle Fade"); 237 | _name[FX_MODE_TWINKLE_FADE_RANDOM] = F("Twinkle Fade Random"); 238 | _name[FX_MODE_SPARKLE] = F("Sparkle"); 239 | _name[FX_MODE_FLASH_SPARKLE] = F("Flash Sparkle"); 240 | _name[FX_MODE_HYPER_SPARKLE] = F("Hyper Sparkle"); 241 | _name[FX_MODE_STROBE] = F("Strobe"); 242 | _name[FX_MODE_STROBE_RAINBOW] = F("Strobe Rainbow"); 243 | _name[FX_MODE_MULTI_STROBE] = F("Multi Strobe"); 244 | _name[FX_MODE_BLINK_RAINBOW] = F("Blink Rainbow"); 245 | _name[FX_MODE_CHASE_WHITE] = F("Chase White"); 246 | _name[FX_MODE_CHASE_COLOR] = F("Chase Color"); 247 | _name[FX_MODE_CHASE_RANDOM] = F("Chase Random"); 248 | _name[FX_MODE_CHASE_RAINBOW] = F("Chase Rainbow"); 249 | _name[FX_MODE_CHASE_FLASH] = F("Chase Flash"); 250 | _name[FX_MODE_CHASE_FLASH_RANDOM] = F("Chase Flash Random"); 251 | _name[FX_MODE_CHASE_RAINBOW_WHITE] = F("Chase Rainbow White"); 252 | _name[FX_MODE_CHASE_BLACKOUT] = F("Chase Blackout"); 253 | _name[FX_MODE_CHASE_BLACKOUT_RAINBOW] = F("Chase Blackout Rainbow"); 254 | _name[FX_MODE_COLOR_SWEEP_RANDOM] = F("Color Sweep Random"); 255 | _name[FX_MODE_RUNNING_COLOR] = F("Running Color"); 256 | _name[FX_MODE_RUNNING_RED_BLUE] = F("Running Red Blue"); 257 | _name[FX_MODE_RUNNING_RANDOM] = F("Running Random"); 258 | _name[FX_MODE_LARSON_SCANNER] = F("Larson Scanner"); 259 | _name[FX_MODE_COMET] = F("Comet"); 260 | _name[FX_MODE_FIREWORKS] = F("Fireworks"); 261 | _name[FX_MODE_FIREWORKS_RANDOM] = F("Fireworks Random"); 262 | _name[FX_MODE_MERRY_CHRISTMAS] = F("Merry Christmas"); 263 | _name[FX_MODE_HALLOWEEN] = F("Halloween"); 264 | _name[FX_MODE_FIRE_FLICKER] = F("Fire Flicker"); 265 | _name[FX_MODE_FIRE_FLICKER_SOFT] = F("Fire Flicker (soft)"); 266 | _name[FX_MODE_FIRE_FLICKER_INTENSE] = F("Fire Flicker (intense)"); 267 | _name[FX_MODE_CIRCUS_COMBUSTUS] = F("Circus Combustus"); 268 | _name[FX_MODE_BICOLOR_CHASE] = F("Bicolor Chase"); 269 | _name[FX_MODE_TRICOLOR_CHASE] = F("Tricolor Chase"); 270 | _name[FX_MODE_ICU] = F("ICU"); 271 | _name[FX_MODE_CUSTOM] = F("Custom"); 272 | _name[FX_MODE_METEOR_RAIN] = F("Meteor Rain"); 273 | 274 | _brightness = DEFAULT_BRIGHTNESS; 275 | _running = false; 276 | _num_segments = 1; 277 | _segments[0].mode = DEFAULT_MODE; 278 | _segments[0].colors[0] = (RgbColor) HtmlColor(DEFAULT_COLOR); 279 | _segments[0].start = 0; 280 | (_strip.PixelCount() >= MAX_PIXEL_CT) ? _segments[0].stop = MAX_PIXEL_CT : _segments[0].stop = _strip.PixelCount() ; 281 | _segments[0].speed = DEFAULT_SPEED; 282 | RESET_RUNTIME; 283 | } 284 | 285 | void init() { 286 | _strip.Begin(); 287 | setBrightness(_brightness); 288 | _strip.Show(); 289 | } 290 | 291 | void service() { 292 | if(_running || _triggered) { 293 | unsigned long now = millis(); // Be aware, millis() rolls over every 49 days 294 | bool doShow = false; 295 | for(uint8_t i=0; i < _num_segments; i++) { 296 | _segment_index = i; 297 | if(now > SEGMENT_RUNTIME.next_time || _triggered) { 298 | doShow = true; 299 | uint16_t delay = (this->*_mode[SEGMENT.mode])(); 300 | SEGMENT_RUNTIME.next_time = now + max((int)delay, SPEED_MIN); 301 | SEGMENT_RUNTIME.counter_mode_call++; 302 | } 303 | } 304 | if(doShow) { 305 | //delay(1); // for ESP32 (see https://forums.adafruit.com/viewtopic.php?f=47&t=117327) 306 | _strip.Show(); 307 | } 308 | _triggered = false; 309 | } 310 | } 311 | 312 | void start() { 313 | RESET_RUNTIME; 314 | _running = true; 315 | } 316 | 317 | void stop() { 318 | _running = false; 319 | strip_off(); 320 | } 321 | 322 | void clear(){ 323 | strip_off(); 324 | } 325 | 326 | void show(){ 327 | _strip.Show(); 328 | } 329 | 330 | void trigger() { 331 | _triggered = true; 332 | } 333 | 334 | void setMode(uint8_t m) { 335 | RESET_RUNTIME; 336 | _segments[0].mode = constrain(m, 0, MODE_COUNT - 1); 337 | setBrightness(_brightness); 338 | } 339 | 340 | void setSpeed(uint16_t s) { 341 | RESET_RUNTIME; 342 | _segments[0].speed = constrain(s, SPEED_MIN, SPEED_MAX); 343 | } 344 | 345 | void increaseSpeed(uint8_t s) { 346 | uint16_t newSpeed = constrain(SEGMENT.speed + s, SPEED_MIN, SPEED_MAX); 347 | setSpeed(newSpeed); 348 | } 349 | 350 | void decreaseSpeed(uint8_t s) { 351 | uint16_t newSpeed = constrain(SEGMENT.speed - s, SPEED_MIN, SPEED_MAX); 352 | setSpeed(newSpeed); 353 | } 354 | 355 | void setBrightness(uint8_t b) { 356 | _brightness = constrain(b, BRIGHTNESS_MIN, BRIGHTNESS_MAX); 357 | _strip.SetBrightness(_brightness); 358 | _strip.Show(); 359 | } 360 | 361 | void increaseBrightness(uint8_t s) { 362 | s = constrain(_brightness + s, BRIGHTNESS_MIN, BRIGHTNESS_MAX); 363 | setBrightness(s); 364 | } 365 | 366 | void decreaseBrightness(uint8_t s) { 367 | s = constrain(_brightness - s, BRIGHTNESS_MIN, BRIGHTNESS_MAX); 368 | setBrightness(s); 369 | } 370 | 371 | void setLength(uint16_t b) { 372 | RESET_RUNTIME; 373 | if (b < 1) b = 1; 374 | _segments[0].start = 0; 375 | _segments[0].stop = b; 376 | } 377 | 378 | void increaseLength(uint16_t s) { 379 | s = _segments[0].stop - _segments[0].start + 1 + s; 380 | setLength(s); 381 | } 382 | 383 | void decreaseLength(uint16_t s) { 384 | if (s > _segments[0].stop - _segments[0].start + 1) s = 1; 385 | s = _segments[0].stop - _segments[0].start + 1 - s; 386 | 387 | for(uint16_t i=_segments[0].start + s; i <= (_segments[0].stop - _segments[0].start + 1); i++) { 388 | this->setPixelColor(i, (RgbColor) HtmlColor(BLACK)); 389 | } 390 | _strip.Show(); 391 | 392 | setLength(s); 393 | } 394 | 395 | uint16_t getLength(void) { 396 | return _segments[0].stop - _segments[0].start + 1; 397 | } 398 | 399 | void setColor(RgbColor c) { 400 | RESET_RUNTIME; 401 | _segments[0].colors[0] = c; 402 | } 403 | 404 | void setColor(uint32_t c) { 405 | RESET_RUNTIME; 406 | _segments[0].colors[0] = (RgbColor) HtmlColor((uint32_t) c); 407 | } 408 | 409 | void setColor(uint8_t r, uint8_t g, uint8_t b) { 410 | setColor(((uint32_t)r << 16) | ((uint32_t)g << 8) | b); 411 | } 412 | 413 | void setPixelColor(uint16_t pixel, uint8_t r, uint8_t g, uint8_t b) { 414 | RgbColor color_tmp(r, g, b); 415 | _strip.SetPixelColor(pixel, color_tmp); 416 | } 417 | 418 | void setPixelColor(uint16_t pixel, RgbColor pixel_rgb_color) { 419 | _strip.SetPixelColor(pixel, pixel_rgb_color); 420 | } 421 | 422 | uint8_t getMode(void) { 423 | return _segments[0].mode; 424 | } 425 | 426 | uint16_t getSpeed(void) { 427 | return _segments[0].speed; 428 | } 429 | 430 | uint8_t getBrightness(void) { 431 | return _brightness; 432 | } 433 | 434 | uint8_t getModeCount(void) { 435 | return MODE_COUNT; 436 | } 437 | 438 | uint32_t getColor(void) { 439 | return _segments[0].colors[0]; 440 | } 441 | 442 | uint16_t numPixels(void){ 443 | return _segments[0].stop - _segments[0].start + 1; 444 | } 445 | 446 | boolean isRunning() { 447 | return _running; 448 | } 449 | 450 | const __FlashStringHelper* getModeName(uint8_t m) { 451 | if(m < MODE_COUNT) { 452 | return _name[m]; 453 | } else { 454 | return F(""); 455 | } 456 | } 457 | 458 | uint8_t getNumSegments() { 459 | return _num_segments; 460 | } 461 | 462 | void setNumSegments(uint8_t n) { 463 | _num_segments = n; 464 | } 465 | 466 | Segment getSegment() { 467 | return SEGMENT; 468 | } 469 | 470 | Segment_runtime getSegmentRuntime() { 471 | return SEGMENT_RUNTIME; 472 | } 473 | 474 | Segment* getSegments() { 475 | return _segments; 476 | } 477 | 478 | void setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode, uint32_t color, uint16_t speed, bool reverse) { 479 | if(n < (sizeof(_segments) / sizeof(_segments[0]))) { 480 | if(n + 1 > _num_segments) _num_segments = n + 1; 481 | _segments[n].start = start; 482 | _segments[n].stop = stop; 483 | _segments[n].mode = mode; 484 | _segments[n].speed = speed; 485 | _segments[n].reverse = reverse; 486 | _segments[n].colors[0] = (RgbColor) HtmlColor(color); 487 | } 488 | } 489 | 490 | void setSegment(uint8_t n, uint16_t start, uint16_t stop, uint8_t mode, const uint32_t colors[], uint16_t speed, bool reverse) { 491 | if(n < (sizeof(_segments) / sizeof(_segments[0]))) { 492 | if(n + 1 > _num_segments) _num_segments = n + 1; 493 | _segments[n].start = start; 494 | _segments[n].stop = stop; 495 | _segments[n].mode = mode; 496 | _segments[n].speed = speed; 497 | _segments[n].reverse = reverse; 498 | 499 | for(uint8_t i=0; i g -> b -> back to r 524 | * Inspired by the Adafruit examples. 525 | */ 526 | RgbColor color_wheel(uint8_t pos) { 527 | pos = 255 - pos; 528 | uint32_t ret_hex; 529 | if(pos < 85) { 530 | ret_hex = ((uint32_t)(255 - pos * 3) << 16) | ((uint32_t)(0) << 8) | (pos * 3); 531 | } else if(pos < 170) { 532 | pos -= 85; 533 | ret_hex = ((uint32_t)(0) << 16) | ((uint32_t)(pos * 3) << 8) | (255 - pos * 3); 534 | } else { 535 | pos -= 170; 536 | ret_hex = ((uint32_t)(pos * 3) << 16) | ((uint32_t)(255 - pos * 3) << 8) | (0); 537 | } 538 | return (RgbColor) HtmlColor((uint32_t) ret_hex); 539 | } 540 | 541 | 542 | /* 543 | * Returns a new, random wheel index with a minimum distance of 42 from pos. 544 | */ 545 | uint8_t get_random_wheel_index(uint8_t pos) { 546 | uint8_t r = 0; 547 | uint8_t x = 0; 548 | uint8_t y = 0; 549 | uint8_t d = 0; 550 | 551 | while(d < 42) { 552 | r = random(256); 553 | x = abs(pos - r); 554 | y = 255 - x; 555 | d = min(x, y); 556 | } 557 | 558 | return r; 559 | } 560 | 561 | private: 562 | T_PIXEL_METHOD& _strip; 563 | 564 | uint8_t 565 | _brightness; 566 | 567 | boolean 568 | _running, 569 | _triggered; 570 | 571 | unsigned long next_time; 572 | 573 | RgbColor colorConverted(uint32_t color) { 574 | RgbColor color_tmp(HtmlColor( _color )); 575 | return color_tmp; 576 | } 577 | 578 | void strip_off() { 579 | _strip.ClearTo(rgbcolor_black); 580 | _strip.Show(); 581 | } 582 | 583 | //////////// Start of Effects //////////// 584 | 585 | /* 586 | * Fades all pixel to Black (percentage rgb) 587 | */ 588 | void fadeToBlack(uint16_t ledNo, byte fadeValue) { 589 | RgbColor oldColor = _strip.GetPixelColor(ledNo); 590 | uint8_t r = (oldColor.R <= 10)? 0 : (uint8_t) oldColor.R - (oldColor.R * fadeValue / 256); 591 | uint8_t g = (oldColor.G <= 10)? 0 : (uint8_t) oldColor.G - (oldColor.G * fadeValue / 256); 592 | uint8_t b = (oldColor.B <= 10)? 0 : (uint8_t) oldColor.B - (oldColor.B * fadeValue / 256); 593 | RgbColor newColor(r, g, b); 594 | _strip.SetPixelColor(ledNo, newColor); 595 | } 596 | 597 | /* 598 | * Fades all pixel to Black (use absolute value) 599 | */ 600 | void fadeToWhiteVal(uint16_t ledNo, uint8_t fadeValue) { 601 | RgbColor color_tmp = _strip.GetPixelColor(ledNo); 602 | if(fadeValue < 10) fadeValue = 0; 603 | color_tmp.Lighten(fadeValue); 604 | _strip.SetPixelColor(ledNo, color_tmp); 605 | } 606 | 607 | /* 608 | * Fades all pixel to Black (percentage rgb) 609 | */ 610 | void fadeToWhite(uint16_t ledNo, byte fadeValue) { 611 | RgbColor oldColor = _strip.GetPixelColor(ledNo); 612 | uint8_t r = (oldColor.R <= 10)? 0 : (uint8_t) oldColor.R + (oldColor.R * fadeValue / 256); 613 | uint8_t g = (oldColor.G <= 10)? 0 : (uint8_t) oldColor.G + (oldColor.G * fadeValue / 256); 614 | uint8_t b = (oldColor.B <= 10)? 0 : (uint8_t) oldColor.B + (oldColor.B * fadeValue / 256); 615 | RgbColor newColor(r, g, b); 616 | _strip.SetPixelColor(ledNo, newColor); 617 | } 618 | 619 | /* 620 | * Fades all pixel to Black (use absolute value) 621 | */ 622 | void fadeToBlackVal(uint16_t ledNo, uint8_t fadeValue) { 623 | RgbColor color_tmp = _strip.GetPixelColor(ledNo); 624 | if(fadeValue < 10) fadeValue = 0; 625 | color_tmp.Darken(fadeValue); 626 | _strip.SetPixelColor(ledNo, color_tmp); 627 | } 628 | 629 | /* 630 | * No blinking. Just plain old static light. 631 | */ 632 | uint16_t mode_static(void) { 633 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 634 | this->setPixelColor(i, SEGMENT.colors[0]); 635 | } 636 | return 500; 637 | } 638 | 639 | /* 640 | * Blink/strobe function 641 | * Alternate between color1 and color2 642 | * if(strobe == true) then create a strobe effect 643 | */ 644 | uint16_t blink(RgbColor color1, RgbColor color2, bool strobe) { 645 | RgbColor color = ((SEGMENT_RUNTIME.counter_mode_call & 1) == 0) ? color1 : color2; 646 | if(SEGMENT.reverse) color = (color == color1) ? color2 : color1; 647 | 648 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 649 | this->setPixelColor(i, color); 650 | } 651 | 652 | if((SEGMENT_RUNTIME.counter_mode_call & 1) == 0) { 653 | return strobe ? 20 : (SEGMENT.speed / 2); 654 | } else { 655 | return strobe ? SEGMENT.speed - 20 : (SEGMENT.speed / 2); 656 | } 657 | } 658 | 659 | /* 660 | * Normal blinking. 50% on/off time. 661 | */ 662 | uint16_t mode_blink(void) { 663 | return blink(SEGMENT.colors[0], SEGMENT.colors[1], false); 664 | } 665 | 666 | /* 667 | * Does the "standby-breathing" of well known i-Devices. Fixed Speed. 668 | * Use mode "fade" if you like to have something similar with a different speed. 669 | */ 670 | uint16_t mode_breath(void) { 671 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // step 672 | uint16_t breath_delay_steps[] = { 7, 9, 13, 15, 16, 17, 18, 930, 19, 18, 15, 13, 9, 7, 4, 5, 10 }; // magic numbers for breathing LED 673 | uint8_t breath_brightness_steps[] = { 150, 125, 100, 75, 50, 25, 16, 15, 16, 25, 50, 75, 100, 125, 150, 220, 255 }; // even more magic numbers! 674 | 675 | if(SEGMENT_RUNTIME.counter_mode_call == 0) { 676 | SEGMENT_RUNTIME.aux_param = breath_brightness_steps[0] + 1; // we use aux_param to store the brightness 677 | } 678 | 679 | uint8_t breath_brightness = SEGMENT_RUNTIME.aux_param; 680 | 681 | if(SEGMENT_RUNTIME.counter_mode_step < 8) { 682 | breath_brightness--; 683 | } else { 684 | breath_brightness++; 685 | } 686 | 687 | // update index of current delay when target brightness is reached, start over after the last step 688 | if(breath_brightness == breath_brightness_steps[SEGMENT_RUNTIME.counter_mode_step]) { 689 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (sizeof(breath_brightness_steps)/sizeof(uint8_t)); 690 | } 691 | 692 | int lum = map(breath_brightness, 0, 255, 0, _brightness); // keep luminosity below brightness set by user 693 | //uint8_t w = (SEGMENT.colors[0].W) * lum / _brightness; // modify RGBW colors with brightness info 694 | uint8_t r = (SEGMENT.colors[0].R) * lum / _brightness; 695 | uint8_t g = (SEGMENT.colors[0].G) * lum / _brightness; 696 | uint8_t b = (SEGMENT.colors[0].B) * lum / _brightness; 697 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 698 | this->setPixelColor(i, r, g, b); 699 | } 700 | 701 | SEGMENT_RUNTIME.aux_param = breath_brightness; 702 | return breath_delay_steps[SEGMENT_RUNTIME.counter_mode_step]; 703 | } 704 | 705 | uint16_t color_wipe(RgbColor color1, RgbColor color2, bool rev) { 706 | if(SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH) { 707 | uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step; 708 | if(SEGMENT.reverse) { 709 | this->setPixelColor(SEGMENT.stop - led_offset, color1); 710 | } else { 711 | this->setPixelColor(SEGMENT.start + led_offset, color1); 712 | } 713 | } else { 714 | uint32_t led_offset = SEGMENT_RUNTIME.counter_mode_step - SEGMENT_LENGTH; 715 | if((SEGMENT.reverse && !rev) || (!SEGMENT.reverse && rev)) { 716 | this->setPixelColor(SEGMENT.stop - led_offset, color2); 717 | } else { 718 | this->setPixelColor(SEGMENT.start + led_offset, color2); 719 | } 720 | } 721 | 722 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % (SEGMENT_LENGTH * 2); 723 | return (SEGMENT.speed / (SEGMENT_LENGTH * 2)); 724 | } 725 | 726 | /* 727 | * Lights all LEDs one after another. 728 | */ 729 | uint16_t mode_color_wipe(void) { 730 | return color_wipe(SEGMENT.colors[0], SEGMENT.colors[1], false); 731 | } 732 | 733 | uint16_t mode_color_wipe_inv(void) { 734 | return color_wipe(SEGMENT.colors[1], SEGMENT.colors[0], false); 735 | } 736 | 737 | uint16_t mode_color_wipe_rev(void) { 738 | return color_wipe(SEGMENT.colors[0], SEGMENT.colors[1], true); 739 | } 740 | 741 | uint16_t mode_color_wipe_rev_inv(void) { 742 | return color_wipe(SEGMENT.colors[1], SEGMENT.colors[0], true); 743 | } 744 | 745 | /* 746 | * Turns all LEDs after each other to a random color. 747 | * Then starts over with another color. 748 | */ 749 | uint16_t mode_color_wipe_random(void) { 750 | if(SEGMENT_RUNTIME.counter_mode_step % SEGMENT_LENGTH == 0) { // aux_param will store our random color wheel index 751 | SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); 752 | } 753 | RgbColor color = color_wheel(SEGMENT_RUNTIME.aux_param); 754 | return color_wipe(color, color, false) * 2; 755 | } 756 | 757 | /* 758 | * Lights all LEDs in one random color up. Then switches them 759 | * to the next random color. 760 | */ 761 | uint16_t mode_random_color(void) { 762 | SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); // aux_param will store our random color wheel index 763 | RgbColor color = color_wheel(SEGMENT_RUNTIME.aux_param); 764 | 765 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 766 | this->setPixelColor(i, color); 767 | } 768 | return (SEGMENT.speed); 769 | } 770 | 771 | /* 772 | * Lights every LED in a random color. Changes one random LED after the other 773 | * to another random color. 774 | */ 775 | uint16_t mode_single_dynamic(void) { 776 | if(SEGMENT_RUNTIME.counter_mode_call == 0) { 777 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 778 | this->setPixelColor(i, color_wheel(random(256))); 779 | } 780 | } 781 | 782 | this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color_wheel(random(256))); 783 | return (SEGMENT.speed); 784 | } 785 | 786 | /* 787 | * Lights every LED in a random color. Changes all LED at the same time 788 | * to new random colors. 789 | */ 790 | uint16_t mode_multi_dynamic(void) { 791 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 792 | this->setPixelColor(i, color_wheel(random(256))); 793 | } 794 | return (SEGMENT.speed); 795 | } 796 | 797 | /* 798 | * Cycles all LEDs at once through a rainbow. 799 | */ 800 | uint16_t mode_rainbow(void) { 801 | RgbColor color = color_wheel(SEGMENT_RUNTIME.counter_mode_step); 802 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 803 | this->setPixelColor(i, color); 804 | } 805 | 806 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF; 807 | return (SEGMENT.speed / 256); 808 | } 809 | 810 | /* 811 | * Cycles a rainbow over the entire string of LEDs. 812 | */ 813 | uint16_t mode_rainbow_cycle(void) { 814 | for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { 815 | RgbColor color = color_wheel(((i * 256 / SEGMENT_LENGTH) + SEGMENT_RUNTIME.counter_mode_step) & 0xFF); 816 | this->setPixelColor(SEGMENT.start + i, color); 817 | } 818 | 819 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF; 820 | return (SEGMENT.speed / 256); 821 | } 822 | 823 | /* 824 | * Runs a single pixel back and forth. 825 | */ 826 | uint16_t mode_scan(void) { 827 | if(SEGMENT_RUNTIME.counter_mode_step > (SEGMENT_LENGTH * 2) - 3) { 828 | SEGMENT_RUNTIME.counter_mode_step = 0; 829 | } 830 | 831 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 832 | this->setPixelColor(i, rgbcolor_black); 833 | } 834 | 835 | int led_offset = SEGMENT_RUNTIME.counter_mode_step - (SEGMENT_LENGTH - 1); 836 | led_offset = abs(led_offset); 837 | 838 | if(SEGMENT.reverse) { 839 | this->setPixelColor(SEGMENT.stop - led_offset, SEGMENT.colors[0]); 840 | } else { 841 | this->setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[0]); 842 | } 843 | 844 | SEGMENT_RUNTIME.counter_mode_step++; 845 | return (SEGMENT.speed / (SEGMENT_LENGTH * 2)); 846 | } 847 | 848 | /* 849 | * Runs two pixel back and forth in opposite directions. 850 | */ 851 | uint16_t mode_dual_scan(void) { 852 | if(SEGMENT_RUNTIME.counter_mode_step > (SEGMENT_LENGTH * 2) - 3) { 853 | SEGMENT_RUNTIME.counter_mode_step = 0; 854 | } 855 | 856 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 857 | this->setPixelColor(i, BLACK); 858 | } 859 | 860 | int led_offset = SEGMENT_RUNTIME.counter_mode_step - (SEGMENT_LENGTH - 1); 861 | led_offset = abs(led_offset); 862 | 863 | this->setPixelColor(SEGMENT.start + led_offset, SEGMENT.colors[0]); 864 | this->setPixelColor(SEGMENT.start + SEGMENT_LENGTH - led_offset - 1, SEGMENT.colors[0]); 865 | 866 | SEGMENT_RUNTIME.counter_mode_step++; 867 | return (SEGMENT.speed / (SEGMENT_LENGTH * 2)); 868 | } 869 | 870 | /* 871 | * Fades the LEDs on and (almost) off again. 872 | */ 873 | uint16_t mode_fade(void) { 874 | int lum = SEGMENT_RUNTIME.counter_mode_step - 31; 875 | lum = 63 - (abs(lum) * 2); 876 | lum = map(lum, 0, 64, min(25, (int)_brightness), _brightness); 877 | 878 | //uint8_t w = (SEGMENT.colors[0] >> 24 & 0xFF) * lum / _brightness; // modify RGBW colors with brightness info 879 | uint8_t r = (SEGMENT.colors[0].R) * lum / _brightness; 880 | uint8_t g = (SEGMENT.colors[0].G) * lum / _brightness; 881 | uint8_t b = (SEGMENT.colors[0].B) * lum / _brightness; 882 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 883 | this->setPixelColor(i, r, g, b); 884 | } 885 | 886 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % 64; 887 | return (SEGMENT.speed / 64); 888 | } 889 | 890 | /* 891 | * theater chase function 892 | */ 893 | uint16_t theater_chase(RgbColor color1, RgbColor color2) { 894 | SEGMENT_RUNTIME.counter_mode_call = SEGMENT_RUNTIME.counter_mode_call % 3; 895 | for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { 896 | if((i % 3) == SEGMENT_RUNTIME.counter_mode_call) { 897 | if(SEGMENT.reverse) { 898 | this->setPixelColor(SEGMENT.stop - i, color1); 899 | } else { 900 | this->setPixelColor(SEGMENT.start + i, color1); 901 | } 902 | } else { 903 | if(SEGMENT.reverse) { 904 | this->setPixelColor(SEGMENT.stop - i, color2); 905 | } else { 906 | this->setPixelColor(SEGMENT.start + i, color2); 907 | } 908 | } 909 | } 910 | 911 | return (SEGMENT.speed / SEGMENT_LENGTH); 912 | } 913 | 914 | /* 915 | * Theatre-style crawling lights. 916 | * Inspired by the Adafruit examples. 917 | */ 918 | uint16_t mode_theater_chase(void) { 919 | return theater_chase(SEGMENT.colors[0], rgbcolor_black); 920 | } 921 | 922 | /* 923 | * Theatre-style crawling lights with rainbow effect. 924 | * Inspired by the Adafruit examples. 925 | */ 926 | uint16_t mode_theater_chase_rainbow(void) { 927 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0xFF; 928 | return theater_chase(color_wheel(SEGMENT_RUNTIME.counter_mode_step), BLACK); 929 | } 930 | 931 | /* 932 | * Running lights effect with smooth sine transition. 933 | */ 934 | uint16_t mode_running_lights(void) { 935 | float radPerLed = (2.0 * 3.14159) / SEGMENT_LENGTH; 936 | for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { 937 | int lum = map((int)(sin((i + SEGMENT_RUNTIME.counter_mode_step) * radPerLed) * 128), -128, 128, 0, 255); 938 | if(SEGMENT.reverse) { 939 | this->setPixelColor(SEGMENT.start + i, (SEGMENT.colors[0].R * lum) / 256, (SEGMENT.colors[0].G * lum) / 256, (SEGMENT.colors[0].B * lum) / 256); 940 | } else { 941 | this->setPixelColor(SEGMENT.stop - i, (SEGMENT.colors[0].R * lum) / 256, (SEGMENT.colors[0].G * lum) / 256, (SEGMENT.colors[0].B * lum) / 256); 942 | } 943 | } 944 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 945 | return (SEGMENT.speed / SEGMENT_LENGTH); 946 | } 947 | 948 | /* 949 | * twinkle function 950 | */ 951 | uint16_t twinkle(RgbColor color) { 952 | if(SEGMENT_RUNTIME.counter_mode_step == 0) { 953 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 954 | this->setPixelColor(i, BLACK); 955 | } 956 | uint16_t min_leds = max(1, SEGMENT_LENGTH / 5); // make sure, at least one LED is on 957 | uint16_t max_leds = max(1, SEGMENT_LENGTH / 2); // make sure, at least one LED is on 958 | SEGMENT_RUNTIME.counter_mode_step = random(min_leds, max_leds); 959 | } 960 | 961 | this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color); 962 | 963 | SEGMENT_RUNTIME.counter_mode_step--; 964 | return (SEGMENT.speed / SEGMENT_LENGTH); 965 | } 966 | 967 | /* 968 | * Blink several LEDs on, reset, repeat. 969 | * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ 970 | */ 971 | uint16_t mode_twinkle(void) { 972 | return twinkle(SEGMENT.colors[0]); 973 | } 974 | 975 | /* 976 | * Blink several LEDs in random colors on, reset, repeat. 977 | * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ 978 | */ 979 | uint16_t mode_twinkle_random(void) { 980 | return twinkle(color_wheel(random(256))); 981 | } 982 | 983 | /* 984 | * fade out function 985 | * fades out the current segment by dividing each pixel's intensity by 2 986 | */ 987 | void fade_out() { 988 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 989 | RgbColor rgbcolortmp = _strip.GetPixelColor(i); 990 | RgbColor color_tmp((uint8_t)(rgbcolortmp.R/2), (uint8_t)(rgbcolortmp.G/2), (uint8_t)(rgbcolortmp.B/2) ); 991 | _strip.SetPixelColor(i, color_tmp); 992 | } 993 | } 994 | 995 | /* 996 | * twinkle_fade function 997 | */ 998 | uint16_t twinkle_fade(RgbColor color) { 999 | fade_out(); 1000 | 1001 | if(random(3) == 0) { 1002 | this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color); 1003 | } 1004 | return (SEGMENT.speed / 8); 1005 | } 1006 | 1007 | 1008 | /* 1009 | * Blink several LEDs on, fading out. 1010 | */ 1011 | uint16_t mode_twinkle_fade(void) { 1012 | return twinkle_fade(SEGMENT.colors[0]); 1013 | } 1014 | 1015 | /* 1016 | * Blink several LEDs in random colors on, fading out. 1017 | */ 1018 | uint16_t mode_twinkle_fade_random(void) { 1019 | return twinkle_fade(color_wheel(random(256))); 1020 | } 1021 | 1022 | /* 1023 | * Blinks one LED at a time. 1024 | * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ 1025 | */ 1026 | uint16_t mode_sparkle(void) { 1027 | this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, rgbcolor_black); 1028 | SEGMENT_RUNTIME.aux_param = random(SEGMENT_LENGTH); // aux_param stores the random led index 1029 | this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[0]); 1030 | return (SEGMENT.speed / SEGMENT_LENGTH); 1031 | } 1032 | 1033 | /* 1034 | * Lights all LEDs in the color. Flashes single white pixels randomly. 1035 | * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ 1036 | */ 1037 | uint16_t mode_flash_sparkle(void) { 1038 | if(SEGMENT_RUNTIME.counter_mode_call == 0) { 1039 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 1040 | this->setPixelColor(i, SEGMENT.colors[0]); 1041 | } 1042 | } 1043 | 1044 | this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, SEGMENT.colors[0]); 1045 | 1046 | if(random(5) == 0) { 1047 | SEGMENT_RUNTIME.aux_param = random(SEGMENT_LENGTH); // aux_param stores the random led index 1048 | this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.aux_param, rgbcolor_white); 1049 | return 20; 1050 | } 1051 | return SEGMENT.speed; 1052 | } 1053 | 1054 | /* 1055 | * Like flash sparkle. With more flash. 1056 | * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ 1057 | */ 1058 | uint16_t mode_hyper_sparkle(void) { 1059 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 1060 | this->setPixelColor(i, SEGMENT.colors[0]); 1061 | } 1062 | 1063 | if(random(5) < 2) { 1064 | for(uint16_t i=0; i < max(1, SEGMENT_LENGTH/3); i++) { 1065 | this->setPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), rgbcolor_white); 1066 | } 1067 | return 20; 1068 | } 1069 | return SEGMENT.speed; 1070 | } 1071 | 1072 | /* 1073 | * Classic Strobe effect. 1074 | */ 1075 | uint16_t mode_strobe(void) { 1076 | return blink(SEGMENT.colors[0], SEGMENT.colors[1], true); 1077 | } 1078 | 1079 | /* 1080 | * Classic Strobe effect. Cycling through the rainbow. 1081 | */ 1082 | uint16_t mode_strobe_rainbow(void) { 1083 | return blink(color_wheel(SEGMENT_RUNTIME.counter_mode_call & 0xFF), SEGMENT.colors[1], true); 1084 | } 1085 | 1086 | /* 1087 | * Strobe effect with different strobe count and pause, controlled by speed. 1088 | */ 1089 | uint16_t mode_multi_strobe(void) { 1090 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 1091 | this->setPixelColor(i, rgbcolor_black); 1092 | } 1093 | 1094 | uint16_t delay = SEGMENT.speed / (2 * ((SEGMENT.speed / 10) + 1)); 1095 | if(SEGMENT_RUNTIME.counter_mode_step < (2 * ((SEGMENT.speed / 10) + 1))) { 1096 | if((SEGMENT_RUNTIME.counter_mode_step & 1) == 0) { 1097 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 1098 | this->setPixelColor(i, SEGMENT.colors[0]); 1099 | } 1100 | delay = 20; 1101 | } else { 1102 | delay = 50; 1103 | } 1104 | } 1105 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % ((2 * ((SEGMENT.speed / 10) + 1)) + 1); 1106 | return delay; 1107 | } 1108 | 1109 | /* 1110 | * Classic Blink effect. Cycling through the rainbow. 1111 | */ 1112 | uint16_t mode_blink_rainbow(void) { 1113 | return blink(color_wheel(SEGMENT_RUNTIME.counter_mode_call & 0xFF), SEGMENT.colors[1], false); 1114 | } 1115 | 1116 | /* 1117 | * color chase function. 1118 | * color1 = background color 1119 | * color2 and color3 = colors of two adjacent leds 1120 | */ 1121 | uint16_t chase(RgbColor color1, RgbColor color2, RgbColor color3) { 1122 | uint16_t a = SEGMENT_RUNTIME.counter_mode_step; 1123 | uint16_t b = (a + 1) % SEGMENT_LENGTH; 1124 | uint16_t c = (b + 1) % SEGMENT_LENGTH; 1125 | if(SEGMENT.reverse) { 1126 | this->setPixelColor(SEGMENT.stop - a, color1); 1127 | this->setPixelColor(SEGMENT.stop - b, color2); 1128 | this->setPixelColor(SEGMENT.stop - c, color3); 1129 | } else { 1130 | this->setPixelColor(SEGMENT.start + a, color1); 1131 | this->setPixelColor(SEGMENT.start + b, color2); 1132 | this->setPixelColor(SEGMENT.start + c, color3); 1133 | } 1134 | 1135 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1136 | return (SEGMENT.speed / SEGMENT_LENGTH); 1137 | } 1138 | 1139 | /* 1140 | * Bicolor chase mode 1141 | */ 1142 | uint16_t mode_bicolor_chase(void) { 1143 | return chase(SEGMENT.colors[0], SEGMENT.colors[1], SEGMENT.colors[2]); 1144 | } 1145 | 1146 | /* 1147 | * White running on _color. 1148 | */ 1149 | uint16_t mode_chase_color(void) { 1150 | return chase(SEGMENT.colors[0], rgbcolor_white, rgbcolor_white); 1151 | } 1152 | 1153 | /* 1154 | * Black running on _color. 1155 | */ 1156 | uint16_t mode_chase_blackout(void) { 1157 | return chase(SEGMENT.colors[0], rgbcolor_black, rgbcolor_black); 1158 | } 1159 | 1160 | /* 1161 | * _color running on white. 1162 | */ 1163 | uint16_t mode_chase_white(void) { 1164 | return chase(rgbcolor_white, SEGMENT.colors[0], SEGMENT.colors[0]); 1165 | } 1166 | 1167 | /* 1168 | * White running followed by random color. 1169 | */ 1170 | uint16_t mode_chase_random(void) { 1171 | if(SEGMENT_RUNTIME.counter_mode_step == 0) { 1172 | SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); 1173 | } 1174 | return chase(color_wheel(SEGMENT_RUNTIME.aux_param), rgbcolor_white, rgbcolor_white); 1175 | } 1176 | 1177 | /* 1178 | * Rainbow running on white. 1179 | */ 1180 | uint16_t mode_chase_rainbow_white(void) { 1181 | uint16_t n = SEGMENT_RUNTIME.counter_mode_step; 1182 | uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1183 | RgbColor color2 = color_wheel(((n * 256 / SEGMENT_LENGTH) + (SEGMENT_RUNTIME.counter_mode_call & 0xFF)) & 0xFF); 1184 | RgbColor color3 = color_wheel(((m * 256 / SEGMENT_LENGTH) + (SEGMENT_RUNTIME.counter_mode_call & 0xFF)) & 0xFF); 1185 | 1186 | return chase(rgbcolor_white, color2, color3); 1187 | } 1188 | 1189 | /* 1190 | * White running on rainbow. 1191 | */ 1192 | uint16_t mode_chase_rainbow(void) { 1193 | uint8_t color_sep = 256 / SEGMENT_LENGTH; 1194 | uint8_t color_index = SEGMENT_RUNTIME.counter_mode_call & 0xFF; 1195 | RgbColor color = color_wheel(((SEGMENT_RUNTIME.counter_mode_step * color_sep) + color_index) & 0xFF); 1196 | 1197 | return chase(color, rgbcolor_white, rgbcolor_white); 1198 | } 1199 | 1200 | /* 1201 | * Black running on rainbow. 1202 | */ 1203 | uint16_t mode_chase_blackout_rainbow(void) { 1204 | uint8_t color_sep = 256 / SEGMENT_LENGTH; 1205 | uint8_t color_index = SEGMENT_RUNTIME.counter_mode_call & 0xFF; 1206 | RgbColor color = color_wheel(((SEGMENT_RUNTIME.counter_mode_step * color_sep) + color_index) & 0xFF); 1207 | 1208 | return chase(color, rgbcolor_black, rgbcolor_black); 1209 | } 1210 | 1211 | /* 1212 | * White flashes running on _color. 1213 | */ 1214 | uint16_t mode_chase_flash(void) { 1215 | const static uint8_t flash_count = 4; 1216 | uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((flash_count * 2) + 1); 1217 | 1218 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 1219 | this->setPixelColor(i, SEGMENT.colors[0]); 1220 | } 1221 | 1222 | uint16_t delay = (SEGMENT.speed / SEGMENT_LENGTH); 1223 | if(flash_step < (flash_count * 2)) { 1224 | if(flash_step % 2 == 0) { 1225 | uint16_t n = SEGMENT_RUNTIME.counter_mode_step; 1226 | uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1227 | if(SEGMENT.reverse) { 1228 | this->setPixelColor(SEGMENT.stop - n, rgbcolor_white); 1229 | this->setPixelColor(SEGMENT.stop - m, rgbcolor_white); 1230 | } else { 1231 | this->setPixelColor(SEGMENT.start + n, rgbcolor_white); 1232 | this->setPixelColor(SEGMENT.start + m, rgbcolor_white); 1233 | } 1234 | delay = 20; 1235 | } else { 1236 | delay = 30; 1237 | } 1238 | } else { 1239 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1240 | } 1241 | return delay; 1242 | } 1243 | 1244 | /* 1245 | * White flashes running, followed by random color. 1246 | */ 1247 | uint16_t mode_chase_flash_random(void) { 1248 | const static uint8_t flash_count = 4; 1249 | uint8_t flash_step = SEGMENT_RUNTIME.counter_mode_call % ((flash_count * 2) + 1); 1250 | 1251 | for(uint16_t i=0; i < SEGMENT_RUNTIME.counter_mode_step; i++) { 1252 | this->setPixelColor(SEGMENT.start + i, color_wheel(SEGMENT_RUNTIME.aux_param)); 1253 | } 1254 | 1255 | uint16_t delay = (SEGMENT.speed / SEGMENT_LENGTH); 1256 | if(flash_step < (flash_count * 2)) { 1257 | uint16_t n = SEGMENT_RUNTIME.counter_mode_step; 1258 | uint16_t m = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1259 | if(flash_step % 2 == 0) { 1260 | this->setPixelColor(SEGMENT.start + n, rgbcolor_white); 1261 | this->setPixelColor(SEGMENT.start + m, rgbcolor_white); 1262 | delay = 20; 1263 | } else { 1264 | this->setPixelColor(SEGMENT.start + n, color_wheel(SEGMENT_RUNTIME.aux_param)); 1265 | this->setPixelColor(SEGMENT.start + m, rgbcolor_black); 1266 | delay = 30; 1267 | } 1268 | } else { 1269 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1270 | 1271 | if(SEGMENT_RUNTIME.counter_mode_step == 0) { 1272 | SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); 1273 | } 1274 | } 1275 | return delay; 1276 | } 1277 | 1278 | /* 1279 | * Random color intruduced alternating from start and end of strip. 1280 | */ 1281 | uint16_t mode_color_sweep_random(void) { 1282 | if(SEGMENT_RUNTIME.counter_mode_step % SEGMENT_LENGTH == 0) { // aux_param will store our random color wheel index 1283 | SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); 1284 | } 1285 | RgbColor color = color_wheel(SEGMENT_RUNTIME.aux_param); 1286 | return color_wipe(color, color, true) * 2; 1287 | } 1288 | 1289 | /* 1290 | * Alternating pixels running function. 1291 | */ 1292 | uint16_t running(RgbColor color1, RgbColor color2) { 1293 | for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { 1294 | if((i + SEGMENT_RUNTIME.counter_mode_step) % 4 < 2) { 1295 | if(SEGMENT.reverse) { 1296 | this->setPixelColor(SEGMENT.start + i, color1); 1297 | } else { 1298 | this->setPixelColor(SEGMENT.stop - i, color1); 1299 | } 1300 | } else { 1301 | if(SEGMENT.reverse) { 1302 | this->setPixelColor(SEGMENT.start + i, color2); 1303 | } else { 1304 | this->setPixelColor(SEGMENT.stop - i, color2); 1305 | } 1306 | } 1307 | } 1308 | 1309 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) & 0x3; 1310 | return (SEGMENT.speed / SEGMENT_LENGTH); 1311 | } 1312 | 1313 | /* 1314 | * Alternating color/white pixels running. 1315 | */ 1316 | uint16_t mode_running_color(void) { 1317 | return running(SEGMENT.colors[0], rgbcolor_white); 1318 | } 1319 | 1320 | /* 1321 | * Alternating red/blue pixels running. 1322 | */ 1323 | uint16_t mode_running_red_blue(void) { 1324 | return running((RgbColor) HtmlColor(RED), (RgbColor) HtmlColor(BLUE)); 1325 | } 1326 | 1327 | /* 1328 | * Alternating red/green pixels running. 1329 | */ 1330 | uint16_t mode_merry_christmas(void) { 1331 | return running((RgbColor) HtmlColor(RED), (RgbColor) HtmlColor(GREEN)); 1332 | } 1333 | 1334 | /* 1335 | * Alternating orange/purple pixels running. 1336 | */ 1337 | uint16_t mode_halloween(void) { 1338 | return running((RgbColor) HtmlColor(PURPLE), (RgbColor) HtmlColor(ORANGE)); 1339 | } 1340 | 1341 | /* 1342 | * Random colored pixels running. 1343 | */ 1344 | uint16_t mode_running_random(void) { 1345 | for(uint16_t i=SEGMENT_LENGTH-1; i > 0; i--) { 1346 | if(SEGMENT.reverse) { 1347 | this->setPixelColor(SEGMENT.stop - i, _strip.GetPixelColor(SEGMENT.stop - i + 1)); 1348 | } else { 1349 | this->setPixelColor(SEGMENT.start + i, _strip.GetPixelColor(SEGMENT.start + i - 1)); 1350 | } 1351 | } 1352 | 1353 | if(SEGMENT_RUNTIME.counter_mode_step == 0) { 1354 | SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param); 1355 | if(SEGMENT.reverse) { 1356 | this->setPixelColor(SEGMENT.stop, color_wheel(SEGMENT_RUNTIME.aux_param)); 1357 | } else { 1358 | this->setPixelColor(SEGMENT.start, color_wheel(SEGMENT_RUNTIME.aux_param)); 1359 | } 1360 | } 1361 | 1362 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step == 0) ? 1 : 0; 1363 | return (SEGMENT.speed / SEGMENT_LENGTH); 1364 | } 1365 | 1366 | /* 1367 | * K.I.T.T. 1368 | */ 1369 | uint16_t mode_larson_scanner(void) { 1370 | fade_out(); 1371 | 1372 | if(SEGMENT_RUNTIME.counter_mode_step < SEGMENT_LENGTH) { 1373 | if(SEGMENT.reverse) { 1374 | this->setPixelColor(SEGMENT.stop - SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]); 1375 | } else { 1376 | this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]); 1377 | } 1378 | } else { 1379 | if(SEGMENT.reverse) { 1380 | this->setPixelColor(SEGMENT.stop - ((SEGMENT_LENGTH * 2) - SEGMENT_RUNTIME.counter_mode_step) + 2, SEGMENT.colors[0]); 1381 | } else { 1382 | this->setPixelColor(SEGMENT.start + ((SEGMENT_LENGTH * 2) - SEGMENT_RUNTIME.counter_mode_step) - 2, SEGMENT.colors[0]); 1383 | } 1384 | } 1385 | 1386 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % ((SEGMENT_LENGTH * 2) - 2); 1387 | return (SEGMENT.speed / (SEGMENT_LENGTH * 2)); 1388 | } 1389 | 1390 | /* 1391 | * Firing comets from one end. 1392 | */ 1393 | uint16_t mode_comet(void) { 1394 | fade_out(); 1395 | 1396 | if(SEGMENT.reverse) { 1397 | this->setPixelColor(SEGMENT.stop - SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]); 1398 | } else { 1399 | this->setPixelColor(SEGMENT.start + SEGMENT_RUNTIME.counter_mode_step, SEGMENT.colors[0]); 1400 | } 1401 | 1402 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1403 | return (SEGMENT.speed / SEGMENT_LENGTH); 1404 | } 1405 | 1406 | /* 1407 | * Fireworks function. 1408 | */ 1409 | uint16_t fireworks(RgbColor color) { 1410 | fade_out(); 1411 | 1412 | uint32_t prevLed, thisLed, nextLed; 1413 | 1414 | for(uint16_t i=SEGMENT.start + 1; i > 2) & 0x3F3F3F; 1427 | thisLed = thisLedhex; 1428 | nextLed = (nextLedhex >> 2) & 0x3F3F3F; 1429 | this->setPixelColor(i, (RgbColor) HtmlColor((uint32_t) (prevLed + thisLed + nextLed))); 1430 | } 1431 | 1432 | if(!_triggered) { 1433 | for(uint16_t i=0; isetPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color); 1436 | } 1437 | } 1438 | } else { 1439 | for(uint16_t i=0; isetPixelColor(SEGMENT.start + random(SEGMENT_LENGTH), color); 1441 | } 1442 | } 1443 | return (SEGMENT.speed / SEGMENT_LENGTH); 1444 | } 1445 | 1446 | /* 1447 | * Firework sparks. 1448 | */ 1449 | uint16_t mode_fireworks(void) { 1450 | RgbColor color = SEGMENT.colors[0]; 1451 | return fireworks(color); 1452 | } 1453 | 1454 | /* 1455 | * Random colored firework sparks. 1456 | */ 1457 | uint16_t mode_fireworks_random(void) { 1458 | RgbColor color = color_wheel(random(256)); 1459 | return fireworks(color); 1460 | } 1461 | 1462 | /* 1463 | * Fire flicker function 1464 | */ 1465 | uint16_t fire_flicker(int rev_intensity) { 1466 | byte lum = max(SEGMENT.colors[0].R, max(SEGMENT.colors[0].G, SEGMENT.colors[0].B)) / rev_intensity; 1467 | for(uint16_t i=SEGMENT.start; i <= SEGMENT.stop; i++) { 1468 | int flicker = random(0, lum); 1469 | this->setPixelColor(i, max(SEGMENT.colors[0].R - flicker, 0), max(SEGMENT.colors[0].G - flicker, 0), max(SEGMENT.colors[0].B - flicker, 0)); 1470 | } 1471 | return (SEGMENT.speed / SEGMENT_LENGTH); 1472 | } 1473 | 1474 | /* 1475 | * Random flickering. 1476 | */ 1477 | uint16_t mode_fire_flicker(void) { 1478 | return fire_flicker(3); 1479 | } 1480 | 1481 | /* 1482 | * Random flickering, less intesity. 1483 | */ 1484 | uint16_t mode_fire_flicker_soft(void) { 1485 | return fire_flicker(6); 1486 | } 1487 | 1488 | /* 1489 | * Random flickering, more intesity. 1490 | */ 1491 | uint16_t mode_fire_flicker_intense(void) { 1492 | return fire_flicker(1.7); 1493 | } 1494 | 1495 | /* 1496 | * Tricolor chase function 1497 | */ 1498 | uint16_t tricolor_chase(RgbColor color1, RgbColor color2, RgbColor color3) { 1499 | for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { 1500 | if((i + SEGMENT_RUNTIME.counter_mode_step) % 6 < 2) { 1501 | if(SEGMENT.reverse) { 1502 | this->setPixelColor(SEGMENT.start + i, color1); 1503 | } else { 1504 | this->setPixelColor(SEGMENT.stop - i, color1); 1505 | } 1506 | } else if((i + SEGMENT_RUNTIME.counter_mode_step) % 6 < 4) { 1507 | if(SEGMENT.reverse) { 1508 | this->setPixelColor(SEGMENT.start + i, color2); 1509 | } else { 1510 | this->setPixelColor(SEGMENT.stop - i, color2); 1511 | } 1512 | } else { 1513 | if(SEGMENT.reverse) { 1514 | this->setPixelColor(SEGMENT.start + i, color3); 1515 | } else { 1516 | this->setPixelColor(SEGMENT.stop - i, color3); 1517 | } 1518 | } 1519 | } 1520 | 1521 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % 6; 1522 | return (SEGMENT.speed / SEGMENT_LENGTH); 1523 | } 1524 | 1525 | /* 1526 | * Tricolor chase mode 1527 | */ 1528 | uint16_t mode_tricolor_chase(void) { 1529 | return tricolor_chase(SEGMENT.colors[0], SEGMENT.colors[1], SEGMENT.colors[2]); 1530 | } 1531 | 1532 | /* 1533 | * Alternating white/red/black pixels running. 1534 | */ 1535 | uint16_t mode_circus_combustus(void) { 1536 | return tricolor_chase((RgbColor) HtmlColor(RED), (RgbColor) HtmlColor(WHITE), (RgbColor) HtmlColor(BLACK)); 1537 | } 1538 | 1539 | /* 1540 | * ICU mode 1541 | */ 1542 | uint16_t mode_icu(void) { 1543 | uint16_t dest = SEGMENT_RUNTIME.counter_mode_step & 0xFFFF; 1544 | 1545 | this->setPixelColor(SEGMENT.start + dest, SEGMENT.colors[0]); 1546 | this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, SEGMENT.colors[0]); 1547 | 1548 | if(SEGMENT_RUNTIME.aux_param == dest) { // pause between eye movements 1549 | if(random(6) == 0) { // blink once in a while 1550 | this->setPixelColor(SEGMENT.start + dest, rgbcolor_black); 1551 | this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, rgbcolor_black); 1552 | return 200; 1553 | } 1554 | SEGMENT_RUNTIME.aux_param = random(SEGMENT_LENGTH/2); 1555 | return 1000 + random(2000); 1556 | } 1557 | 1558 | this->setPixelColor(SEGMENT.start + dest, rgbcolor_black); 1559 | this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, rgbcolor_black); 1560 | 1561 | if(SEGMENT_RUNTIME.aux_param > SEGMENT_RUNTIME.counter_mode_step) { 1562 | SEGMENT_RUNTIME.counter_mode_step++; 1563 | dest++; 1564 | } else if (SEGMENT_RUNTIME.aux_param < SEGMENT_RUNTIME.counter_mode_step) { 1565 | SEGMENT_RUNTIME.counter_mode_step--; 1566 | dest--; 1567 | } 1568 | 1569 | this->setPixelColor(SEGMENT.start + dest, SEGMENT.colors[0]); 1570 | this->setPixelColor(SEGMENT.start + dest + SEGMENT_LENGTH/2, SEGMENT.colors[0]); 1571 | 1572 | return (SEGMENT.speed / SEGMENT_LENGTH); 1573 | } 1574 | 1575 | /* 1576 | * Custom mode 1577 | */ 1578 | uint16_t (*customMode)(void) = NULL; 1579 | uint16_t mode_custom() { 1580 | if(customMode == NULL) { 1581 | return 1000; // if custom mode not set, do nothing 1582 | } else { 1583 | return customMode(); 1584 | } 1585 | } 1586 | 1587 | /* 1588 | * Meteor Rain 1589 | * https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain 1590 | */ 1591 | 1592 | uint16_t meteorRain(uint8_t meteorTrailDecay, boolean meteorRandomDecay) { 1593 | uint16_t meteorSize = SEGMENT_LENGTH * 0.15; 1594 | 1595 | if(SEGMENT_RUNTIME.counter_mode_step == 0){ 1596 | _strip.ClearTo(rgbcolor_black); 1597 | } 1598 | 1599 | if( SEGMENT_RUNTIME.counter_mode_step <= SEGMENT_LENGTH*2 ) { 1600 | // fade brightness all LEDs one step 1601 | for(uint16_t i=0; i <= SEGMENT_LENGTH; i++) { 1602 | if( (!meteorRandomDecay) || (random(10)>5) ) { 1603 | fadeToBlackVal(i, meteorTrailDecay ); 1604 | } 1605 | } 1606 | // draw meteor 1607 | for(uint16_t i = 0; i <= meteorSize; i++) { 1608 | if( ( (SEGMENT_RUNTIME.counter_mode_step)-i <= SEGMENT_LENGTH) && ((SEGMENT_RUNTIME.counter_mode_step)-i >= 0) ) { 1609 | if(!SEGMENT.reverse){ 1610 | this->setPixelColor(SEGMENT_RUNTIME.counter_mode_step - i, SEGMENT.colors[0]); 1611 | } else { 1612 | this->setPixelColor(SEGMENT_LENGTH - SEGMENT_RUNTIME.counter_mode_step + i, SEGMENT.colors[0]); 1613 | } 1614 | } 1615 | } 1616 | } 1617 | 1618 | SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH; 1619 | return (SEGMENT.speed / SEGMENT_LENGTH); 1620 | } 1621 | 1622 | uint16_t mode_meteor_rain(void) { 1623 | return meteorRain(64, true); 1624 | } 1625 | 1626 | //////////// End of Effects //////////// 1627 | 1628 | const __FlashStringHelper* 1629 | _name[MODE_COUNT]; // SRAM footprint: 2 bytes per element 1630 | 1631 | mode_ptr 1632 | _mode[MODE_COUNT]; // SRAM footprint: 4 bytes per element 1633 | 1634 | uint8_t _segment_index = 0; 1635 | uint8_t _num_segments = 1; 1636 | segment _segments[MAX_NUM_SEGMENTS]; 1637 | segment_runtime _segment_runtimes[MAX_NUM_SEGMENTS]; 1638 | RgbColor rgbcolor_black = (RgbColor) (HtmlColor(BLACK)); 1639 | RgbColor rgbcolor_white = (RgbColor) (HtmlColor(WHITE)); 1640 | RgbColor rgbcolor_default = (RgbColor) (HtmlColor(DEFAULT_COLOR)); 1641 | }; 1642 | #endif --------------------------------------------------------------------------------