forked from alonf/WebControlledSwitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLedsLogger.cpp
More file actions
36 lines (30 loc) · 764 Bytes
/
Copy pathLedsLogger.cpp
File metadata and controls
36 lines (30 loc) · 764 Bytes
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
#include "LedsLogger.h"
LedsLogger::Led::Led(int ledPin): _ledPin(ledPin)
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, _ledValue);
}
void LedsLogger::Led::Update()
{
if (_times == 0 || millis() - _startTime < _blinkDelay)
return;
_startTime = millis();
_ledValue = _ledValue == HIGH ? LOW : HIGH;
digitalWrite(_ledPin, _ledValue);
--_times;
if (_times == 0) //at the end, set the led to the last value
digitalWrite(_ledPin, _ledValue);
}
void LedsLogger::Led::Blink(int times, int delay)
{
digitalWrite(_ledPin, LOW);
_blinkDelay = delay;
_times = times * 2; //each one is two: on and off
_startTime = millis();
}
void LedsLogger::Led::Set(int value)
{
_times = 0; //stop blinking
_ledValue = value;
digitalWrite(_ledPin, _ledValue);
}