7#include <initializer_list>
11template <
unsigned int SET_SIZE>
25 LEDSet(std::initializer_list<unsigned int> pins)
27 std::copy(std::begin(pins), std::end(pins),
const_cast<int*
>(
LEDs));
28 for(
unsigned int i = 0; i < this->
size(); i++)
37 unsigned int size() __attribute__((always_inline))
39 return std::distance(std::begin(
LEDs), std::end(
LEDs));
46 for(
unsigned int i = 0; i <
size(); i++)
48 pinMode(
LEDs[i], OUTPUT);
59 for(
unsigned int i = 0; i <
size(); i++)
63 pinMode(
LEDs[i], OUTPUT);
73 for(
unsigned int i = 0; i <
size(); i++)
77 pinMode(
LEDs[i], OUTPUT);
88 for(
unsigned int i = 0; i <
size(); i++)
102 pinMode(pin, OUTPUT);
104 digitalWrite(pin,
State[index]);
109 digitalWrite(pin,
State[index]);
129 inline void dim(
int pin,
unsigned int analog_val)
134 analogWrite(pin, analog_val);
143 for(
unsigned int i = 1; i <
size(); i++)
147 analogWrite(
LEDs[i], analog_val);
157 int cycles = (time_s * 1000) / 50;
158 int steps = int(
double(255 - end_analog_val)/cycles);
160 volatile int analog_val = 255;
162 for(
int j = 0; j < cycles-1; j++)
190 inline void set_all() __attribute__((always_inline))
192 for(
unsigned int i = 0; i <
size(); i++)
194 pinMode(
LEDs[i], OUTPUT);
195 digitalWrite(
LEDs[i], HIGH);
204 for(
unsigned int i = 0; i <
size(); i++)
206 pinMode(
LEDs[i], OUTPUT);
207 digitalWrite(
LEDs[i], LOW);
215 inline void set(
int led_pin) __attribute__((always_inline))
220 pinMode(led_pin, OUTPUT);
221 digitalWrite(led_pin, HIGH);
228 void unset(
int led_pin) __attribute__((always_inline))
233 pinMode(led_pin, OUTPUT);
234 digitalWrite(led_pin, LOW);
242 void set(
int led_pin1,
int led_pin2) __attribute__((always_inline))
247 if(index1 != -1 && index2 != -1)
249 pinMode(led_pin1, OUTPUT);
250 pinMode(led_pin2, OUTPUT);
251 digitalWrite(led_pin1, HIGH);
252 digitalWrite(led_pin2, HIGH);
262 void unset(
int led_pin1,
int led_pin2) __attribute__((always_inline))
267 if(index1 != -1 && index2 != -1)
269 pinMode(led_pin1, OUTPUT);
270 pinMode(led_pin2, OUTPUT);
272 digitalWrite(led_pin1, LOW);
273 digitalWrite(led_pin2, LOW);
284 void set(
int led_pin1,
int led_pin2,
int led_pin3) __attribute__((always_inline))
290 if(index1 != -1 && index2 != -1 && index3 != -1)
292 pinMode(led_pin1, OUTPUT);
293 pinMode(led_pin2, OUTPUT);
294 pinMode(led_pin3, OUTPUT);
296 digitalWrite(led_pin1, HIGH);
297 digitalWrite(led_pin2, HIGH);
298 digitalWrite(led_pin3, HIGH);
308 void unset(
int led_pin1,
int led_pin2,
int led_pin3) __attribute__((always_inline))
314 if(index1 != -1 && index2 != -1 && index3 != -1)
316 pinMode(led_pin1, OUTPUT);
317 pinMode(led_pin2, OUTPUT);
318 pinMode(led_pin3, OUTPUT);
320 digitalWrite(led_pin1, LOW);
321 digitalWrite(led_pin2, LOW);
322 digitalWrite(led_pin3, LOW);
339 this->Error_State =
true;
349 if(this->Error_State)
351 for(
unsigned int i = 0; i < 10; i++)
359 #if ABORT_ON_ERROR == 1
378 for(
unsigned int i = 0; i <
size(); i++)
Definition: ledset.hpp:13
unsigned int size() __attribute__((always_inline))
Returns the size of the led sets.
Definition: ledset.hpp:37
LEDSet(std::initializer_list< unsigned int > pins)
Constructor for LEDSet class.
Definition: ledset.hpp:25
void ON_todigital()
Sets all leds with states (ON == 1) and (Analog == 2) to (ON == 1).
Definition: ledset.hpp:71
void unset(int led_pin1, int led_pin2, int led_pin3) __attribute__((always_inline))
Turn-FF three LED Pins simultaneously.
Definition: ledset.hpp:308
void dim_all_routine(unsigned int end_analog_val, double time_s)
Definition: ledset.hpp:155
int fetch_index(int pin) __attribute__((always_inline))
Retrive data structure index based on the pin number. Returns -1 if the pin was not found.
Definition: ledset.hpp:376
void state_reload()
Sets the LEDs based on the value of the corresponding state variable. This function is useful when th...
Definition: ledset.hpp:57
void set(int led_pin1, int led_pin2, int led_pin3) __attribute__((always_inline))
Turn-ON three LED Pins simultaneously.
Definition: ledset.hpp:284
void toggle_twice(int pin, double time_ms)
Toggles the state of a particular LED. This is a pure digital function and destroys all Analog dim st...
Definition: ledset.hpp:97
void toggle_all_routine(int delay_ms)
Definition: ledset.hpp:118
unsigned int State[SET_SIZE]
ON-OFF/Analog states for all LEDs.
Definition: ledset.hpp:19
void max_bright_all()
Sets maximum brightness for all ON-LEDs.
Definition: ledset.hpp:173
const int LEDs[SET_SIZE]
LED pins.
Definition: ledset.hpp:18
void dim(int pin, unsigned int analog_val)
dims a particular valid led pin.
Definition: ledset.hpp:129
void set(int led_pin) __attribute__((always_inline))
Turn-ON a particular LED Pin.
Definition: ledset.hpp:215
void min_bright_all()
Definition: ledset.hpp:180
void set(int led_pin1, int led_pin2) __attribute__((always_inline))
Turn-ON two LED Pins simultaneously. The function only works if both the Pins are valid pins.
Definition: ledset.hpp:242
void error(int pin)
Special function that sets a valid pin and sets the flag LedSet::Error_State to true....
Definition: ledset.hpp:332
void unset_all() __attribute__((always_inline))
Definition: ledset.hpp:202
void unset(int led_pin) __attribute__((always_inline))
Turn-OFF a particular LED Pin.
Definition: ledset.hpp:228
void init()
Sets up the pin mode of all LEDs.
Definition: ledset.hpp:44
void set_all() __attribute__((always_inline))
Turn on all available LEDs.
Definition: ledset.hpp:190
void assert_errors()
Special function that initiates a special routine if the device is in the Error State....
Definition: ledset.hpp:347
bool is_valid_pin(int pin)
Returns whether the given pin is a "valid pin". A valid pin is a pin that is registered with the LEDS...
Definition: ledset.hpp:367
void unset(int led_pin1, int led_pin2) __attribute__((always_inline))
Turn-OFF two LED Pins simultaneously.
Definition: ledset.hpp:262
void dim_all(unsigned int analog_val)
Dims the ON-LEDs with the provided analog voltage. Only affects LEDs that are ON or on Analog Mode.
Definition: ledset.hpp:141
ledstate_t
Definition: ledset.hpp:16
@ ON
Definition: ledset.hpp:16
@ Analog
Definition: ledset.hpp:16
@ OFF
Definition: ledset.hpp:16
void toggle_all()
Toggles the state of all the LEDs. This is a pure digital function and destroys all Analog dim states...
Definition: ledset.hpp:86
bool Error_State
Whether the LED Panel is in an error state.
Definition: ledset.hpp:20
const int LOOP_LED
Definition: pins.hpp:30
const int SAFE_OUTPUT_DUMP_PIN
Definition: pins.hpp:15