FastLED 3.9.15
Loading...
Searching...
No Matches
transition.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/namespace.h"
4#include <stdint.h>
5
6namespace fl {
7
8// Logic to control the progression of a transition over time.
9class Transition {
10 public:
13
14 uint8_t getProgress(uint32_t now) {
15 if (mNotStarted) {
16 return 0;
17 }
18 if (now < mStart) {
19 return 0;
20 } else if (now >= mStart + mDuration) {
21 return 255;
22 } else {
23 return ((now - mStart) * 255) / mDuration;
24 }
25 }
26
27 void start(uint32_t now, uint32_t duration) {
28 mNotStarted = false;
29 mStart = now;
30 mDuration = duration;
31 }
32
33 void end() { mNotStarted = true; }
34
35 bool isTransitioning(uint32_t now) {
36 if (mNotStarted) {
37 return false;
38 }
39 return now >= mStart && now < mStart + mDuration;
40 }
41
42 private:
43 uint32_t mStart;
44 uint32_t mDuration;
46};
47
48} // namespace fl
uint32_t mDuration
Definition transition.h:44
bool isTransitioning(uint32_t now)
Definition transition.h:35
uint8_t getProgress(uint32_t now)
Definition transition.h:14
void start(uint32_t now, uint32_t duration)
Definition transition.h:27
uint32_t mStart
Definition transition.h:43
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16