-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLed.cpp
64 lines (58 loc) · 1.19 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
61
62
63
64
/*
* Project: ReflowOven
* File: Led.cpp
* Author: Sandro Lutz
*/
#include "Led.h"
Led::Led(uint8_t pin)
{
_pin = pin;
pinMode(pin, OUTPUT);
off();
}
void Led::on()
{
_onTime = 0;
_offTime = 0;
digitalWrite(_pin, LOW);
_changeTime = millis();
}
void Led::off()
{
_onTime = 0;
_offTime = 0;
digitalWrite(_pin, HIGH);
_changeTime = millis();
}
void Led::toggle()
{
_onTime = 0;
_offTime = 0;
digitalWrite(_pin, !(digitalRead(_pin) & HIGH));
_changeTime = millis();
}
void Led::setPattern(unsigned int onTime, unsigned int offTime) {
if(onTime == 0) {
return off();
}
if(offTime == 0) {
return on();
}
_onTime = onTime;
_offTime = offTime;
}
void Led::update() {
if(_onTime != 0 && _offTime != 0) {
if (digitalRead(_pin) == LOW) {
if (getTimeDifference(_changeTime, millis()) >= _onTime) {
digitalWrite(_pin, HIGH);
_changeTime = millis();
}
} else {
if (getTimeDifference(_changeTime, millis()) >= _offTime) {
digitalWrite(_pin, LOW);
_changeTime = millis();
}
}
}
}