GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — FastLED Wave Functions FastLED Wave Functions
zackees edited this page
LED projects often benefit from smooth wave functions to control colors, brightnesses, motion, or other aspects of an animation. FastLED provides a number of fast, efficient, smooth wave functions. Of particular note are sin8/cos8 and sin16/cos16. These are high-performance integer approximations of 'sine' and 'cosine', when those particular wave functions are needed. However, FastLED also offers several other wave functions which may be better suited for some animations. Typically, animation code found 'in the wild' uses floating point sine and cosine waves -- mostly because (1) they look nice, and (2) sine and cosine functions are often 'built in' to many environments. Sine and cosine are rarely chosen for use in an animation because those exact trigonometric relationships are needed! You should experiment with different wave functions, and see which ones look best to you, and perform best in your projects.
In order from fastest to slowest, here are the wave functions that FastLED provides: All FastLED wave functions treat the input as a position along one full cycle of the wave. For the 8-bit functions, input A common pattern is therefore: uint8_t t = millis() / 4; // 1 cycle every 1024 ms uint8_t bri = sin8(t); // 0..255 brightness that smoothly oscillates You don't need to wrap or modulo the input — unsigned overflow already gives you free wraparound. These functions take an 8-bit unsigned integer (uint8_t) and return an 8-bit unsigned integer (uint8_t). Input range is
Depending on context and usage, these wave functions can be as fast or faster than using a lookup table to generate wave values. (And they use a heck of a lot less RAM.) Since particular projects and code differ greatly, you are encouraged to try different options and select the one that works best in your particular circumstances. There is no uint8_t rising = i; // 0..255, snaps back to 0 — a sawtooth uint8_t falling = 255 - i; // 255..0, snaps back to 255 — the reverse ramp Every other function on this page is a reshaping of that ramp — What you usually want in practice is the time-driven sawtooth, which does have a name:
uint8_t saw = beat8(60); // sawtooth at 60 BPM uint8_t tri = triwave8(beat8(60)); // triangle at 60 BPM uint8_t ease = quadwave8(beat8(60)); // eased, ~sine, at 60 BPM These functions take an 16-bit unsigned integer (uint16_t) and return a signed 16-bit integer (int16_t). Input range is
Clone this wiki locally |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |