-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyLED.cpp
79 lines (72 loc) · 1.37 KB
/
myLED.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "myLED.h"
MyLED::MyLED(USHORT pin = 1)
:pinNumber(pin)
{
pinMode(pin, OUTPUT);
}
void MyLED::turnOn(void)
{
status = ON;
}
void MyLED::turnOff(void)
{
status = OFF;
}
void MyLED::toggle(void)
{
if (status == OFF)
{
status = ON;
}
else
{
status = OFF;
}
}
void MyLED::blink(ULONG duration)
{
status = BLINK;
blinkDur = duration;
}
void MyLED::writeOut(void)
{
/* write output only on event */
if ((statusK1 != ON) && (status == ON))
{
digitalWrite(pinNumber, HIGH);
}
else if ((statusK1 != OFF) && (status == OFF))
{
digitalWrite(pinNumber, LOW);
}
/* blinking start */
else if ((statusK1 != BLINK) && (status == BLINK))
{
tStartBlink = millis();
if (statusK1 == OFF)
{
blinkType = OFF_ON_OFF;
digitalWrite(pinNumber, HIGH);
}
else
{
blinkType = ON_OFF_ON;
digitalWrite(pinNumber, LOW);
}
}
/* blinking in progress */
else if ((status == BLINK) && ((millis() - tStartBlink) > blinkDur))
{
if (blinkType == ON_OFF_ON)
{
digitalWrite(pinNumber, HIGH);
status = ON;
}
else
{
digitalWrite(pinNumber, LOW);
status = OFF;
}
}
statusK1 = status;
}