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 "fl/stdint.h"
5#include "fl/int.h"
6
7namespace fl {
8
9// Logic to control the progression of a transition over time.
11 public:
14
15 uint8_t getProgress(fl::u32 now) {
16 if (mNotStarted) {
17 return 0;
18 }
19 if (now < mStart) {
20 return 0;
21 } else if (now >= mStart + mDuration) {
22 return 255;
23 } else {
24 return ((now - mStart) * 255) / mDuration;
25 }
26 }
27
28 void start(fl::u32 now, fl::u32 duration) {
29 mNotStarted = false;
30 mStart = now;
31 mDuration = duration;
32 }
33
34 void end() { mNotStarted = true; }
35
36 bool isTransitioning(fl::u32 now) {
37 if (mNotStarted) {
38 return false;
39 }
40 return now >= mStart && now < mStart + mDuration;
41 }
42
43 private:
44 fl::u32 mStart;
45 fl::u32 mDuration;
47};
48
49} // namespace fl
uint8_t getProgress(fl::u32 now)
Definition transition.h:15
void start(fl::u32 now, fl::u32 duration)
Definition transition.h:28
bool isTransitioning(fl::u32 now)
Definition transition.h:36
fl::u32 mStart
Definition transition.h:44
fl::u32 mDuration
Definition transition.h:45
Implements the FastLED namespace macros.
IMPORTANT!
Definition crgb.h:20