blob: baf03e97b982d915c3ab7efe8c607de6c1fc7e64 (
plain)
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
|
#include <Arduino.h>
class LedControl
{
public:
LedControl(int pin, int high = HIGH, int init = LOW)
{
_pin = pin;
_high = high;
pinMode(_pin, OUTPUT);
(init == high) ? on() : off();
}
void set(int state)
{
_state = state;
digitalWrite(_pin, state);
}
void off() { set(!_high); }
void on() { set(_high); }
void toggle() { (_state == _high) ? off() : on(); }
void blink(const unsigned long interval)
{
static unsigned long previous_millis = 0;
unsigned long current_millis = millis();
if (current_millis - previous_millis >= interval)
{
previous_millis = current_millis;
toggle();
}
}
private:
int _state;
int _high;
int _pin;
};
|