-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.cpp
60 lines (51 loc) · 1.05 KB
/
led.cpp
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
#include "led.h"
void Led::Setup(int led_pin)
{
_led_pin = led_pin;
pinMode(_led_pin, OUTPUT);
LedOff();
_winkCurrent = 0 ;
_winkNumber = 0 ;
_wakeup = 0;
_currentTime = 0;
_prevTime = 0 ;
}
void Led::CyclTask(void)
{
unsigned long time = millis();
_currentTime += (time - _prevTime);
_prevTime = time;
if(_currentTime > _wakeup)
{
_currentTime = 0;
if(_led_is_on == true)
{
LedOff();
_wakeup = (_winkCurrent > 0) ? _delay_between_two_wink :
_delay_between_two_cycle;
}
else
{
_wakeup = _delay_wink;
if(_winkCurrent > 0)
{
LedOn();
_winkCurrent--;
}
else
{
_winkCurrent = _winkNumber;
}
}
}
}
void Led::LedOff(void)
{
_led_is_on = false;
digitalWrite(_led_pin, LOW);
}
void Led::LedOn(void)
{
_led_is_on = true;
digitalWrite(_led_pin, HIGH);
}