-
Notifications
You must be signed in to change notification settings - Fork 0
/
rainbow.h
80 lines (64 loc) · 2.36 KB
/
rainbow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \
* Implementation of a simple shifting solid colour effect. *
* *
* Author: Kip (https://github.com/kip93/). *
* Source: https://github.com/kip93/lamp/ *
* License: BSD 3-Clause *
\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef RAINBOW_H_
#define RAINBOW_H_
#include "effect.h" // Abstract effect structure.
/**
* Effect implementation that shows a slowly changing solid colour.
*/
class Rainbow : public Effect {
public: ///////////////////////////////////////////////////////////////////////
/**
* Destructor. Free up resources.
*/
~Rainbow() {
delete callback;
}
/**
* Update the contents of the LED matrix.
*/
void update() {
fill(callback);
show(2); // Show changes and keep the code to ~2 FPS.
callback -> update();
}
private: //////////////////////////////////////////////////////////////////////
/**
* Effect callback that will compute and show the correct colour.
*/
class Callback : public FillCallback {
public:
/**
* Callback function. Shows the current colour.
*
* @param i The row index.
* @param j The column index.
*
* @returns An RGB colour to be set at the given coordinates.
*/
CRGB call(uint8_t i, uint8_t j) {
return interpolate_colour(RainbowColors_p, index);
}
/**
* Shift to the next colour.
*/
void update() {
index += 1;
}
private:
/**
* The current colour to be shown.
*/
uint8_t index = 0;
};
/**
* The callback instance to be sent to the parent class.
*/
Callback * const callback = new Callback();
};
#endif // RAINBOW_H_