-
Notifications
You must be signed in to change notification settings - Fork 1
/
FluxCapacitor.h
265 lines (218 loc) · 7.29 KB
/
FluxCapacitor.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/**
* ----------------------------------------------------------------
* Copyright (C) 2020 Luis Acosta <zerfoinder@gmail.com>
*
* FluxCapacitor library, This library for Arduino is used to manage leds to emulate
* Back to the Future's Flux Capacitor
*
* www.github.com/Zerfoinder/TimeMachine_FluxCapacitor (github as default source provider)
*
* This file is part of FluxCapacitor library.
*
* FluxCapacitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FluxCapacitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* ----------------------------------------------------------------
*/
/**
* name: FluxCapacitor
* version: 0.1.1
* Author: Luis Acosta <zerfoinder@gmail.com>
* Date: 2020-07-22
* Description: FluxCapacitor is an Arduino Library to manage leds to emulate Back to the Future's Flux Capacitor.
*/
#ifndef TIMEMACHINE_FLUX_CAPACITOR_H
#define TIMEMACHINE_FLUX_CAPACITOR_H
#include <EasyPin.h>
using namespace zsoft::io::utilities;
namespace bttf::timemachine {
/**
* @brief FluxType is an enum to define number of leds
*/
enum FluxType {
FIVE_LEDS = 0, // FIVE LEDS FLUX CAPACITOR
FOUR_LEDS = 1, // FOUR LEDS FLUX CAPACITOR
//ONE_LED = 2 // ONE LED FLUX CAPACITOR
};
/** FluxType is an enum to define pin mode. */
/**
* @brief FluxState indicates the current state of Flux.
*/
enum FluxState {
STOPPED = 0, // Flux Capacitor is OFF (All LEDs OFF).
RUNNING = 1, // Flux Capacitor is running a sequence.
FLASHING = 2 // Flux Capacitor is flashing.
};
/**
* @brief This class describes a flux capacitor.
*/
class FluxCapacitor {
/** -------------- CONSTANTS --------------- */
/**
* brightness level array
*/
static const byte ledBrightness[];
/**
* blink speed level array
*/
static const byte ledBlinkSpeed[];
/**
* Flux Capacitor MAX_LEVEL to reach.
*/
static const byte MAX_LEVEL = 8;
/**
* Flashing duration milliseconds
*/
static const unsigned long defaultFlashingDuration = 200;
public:
// /**
// * @brief Constructs a new instance.
// *
// * @param[in] pinNumber The pin number in Arduino board.
// */
//FluxCapacitor(byte pinNumber);
/**
* @brief Constructs a new instance for 4 LEDs.
*
* @param[in] pinNumberCentral The Arduino pin number for LED Central
* @param[in] pinNumberA The Arduino pin number for LED A
* @param[in] pinNumberB The Arduino pin number for LED B
* @param[in] pinNumberC The Arduino pin number for LED C
*/
FluxCapacitor(byte pinNumberCentral, byte pinNumberA, byte pinNumberB, byte pinNumberC);
/**
* @brief Constructs a new instance for 5 LEDs.
*
* @param[in] pinNumberCentral The Arduino pin number for LED Central
* @param[in] pinNumberA The Arduino pin number for LED A
* @param[in] pinNumberB The Arduino pin number for LED B
* @param[in] pinNumberC The Arduino pin number for LED C
* @param[in] pinNumberD The Arduino pin number for LED D
*/
FluxCapacitor(byte pinNumberCentral, byte pinNumberA, byte pinNumberB, byte pinNumberC, byte pinNumberD);
/**
* @brief Initializes the object.
* @warning It should ALWAYS run in setup() section.
*/
void init(void);
/**
* @brief Turns on Flux Capacitor.
* @
*/
void on(void);
/**
* @brief Turns off Flux Capacitor.
*/
void off(void);
/**
* @brief All Flux Capacitor flash for default milliseconds.
*
* @note All LEDs in flux capacitor turn on at the sametime for a short period.
*/
void flash(void);
/**
* @brief All Flux Capacitor flash for N milliseconds.
*
* @param[in] duration Milliseconds flashing duration.
*/
void flash(unsigned long duration);
/**
* @brief Set Flux Capacitor level.
*
* @param[in] level Level to set. (0-8).
*/
void setLevel(byte level);
/**
* @brief Set Flux Capacitor to next level.
*/
void next(void);
/**
* @brief Returns the current Flux Capacitor level.
*
* @return The current Flux Capacitor level.
*/
byte level(void);
/**
* @brief Number of LEDs in Flux Capacitor.
*
* @return The number of LEDs.
*/
int leds(void);
/**
* @brief Get the current state of Flux Capacitor.
*
* @return STOPPED, RUNNING or FLASHING.
* @see [FluxState]
*/
FluxState state(void);
/**
* @brief function used to manage concurrent actions
*
* @warning it should be ALWAYS added in the end of sketch loop() method.
*/
void loop(void);
protected:
private:
/************ METHODS ***************/
/**
* @brief Updates FluxCapacitor state.
*/
void _update(void);
/**
* @brief Increase LED iterator (_ledIterator)
*/
void _nextLed(void);
/**
* @brief Sets the center led brightness.
*/
void _setCenterLedBrightness(void);
/************ PROPERTIES ***************/
/**
* Flux Type
*/
FluxType _fluxType;
/**
* Number of LEDs
*/
int _leds;
/**
* EasyPin array
*/
EasyPin _pins[5];
/************ VARIABLES ***************/
/**
* Flux Capacitor level
*/
byte _level;
/**
* Flux Capacitor state
*/
FluxState _state;
/**
* Led Iterator for LEDs array
*/
byte _ledIterator;
/**
* local variable used to save last loop millis()
*/
unsigned long _lastLoopMillis = 0;
/**
* Variables used for flashing
*/
unsigned long _flashingMillis = 0;
FluxState _backupState = STOPPED;
/**
* local variable for center LED brightness
*/
int _centerLedBrightness = 0;
}; // end class FluxCapacitor
} // end namespace bttf::timemachine
#endif // TIMEMACHINE_FLUX_CAPACITOR_H