generated from JohnMidity/ArduinoModules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLedBlinker.cpp
52 lines (42 loc) · 960 Bytes
/
LedBlinker.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
#include "LedBlinker.h"
LedBlinker::LedBlinker(int ledPin)
{
setup(ledPin, 1000, 1000);
}
LedBlinker::LedBlinker(int ledPin, int interval)
{
setup(ledPin, interval, interval);
}
LedBlinker::LedBlinker(int ledPin, int onInterval, int offInterval)
{
setup(ledPin, onInterval, offInterval);
}
void LedBlinker::setup(int ledPin, int onInterval, int offInterval)
{
_ledPin = ledPin;
_onInterval = onInterval;
_offInterval = offInterval;
_ledState = LOW;
_previousMillis = 0;
pinMode(_ledPin, OUTPUT);
}
void LedBlinker::moduleLoop()
{
unsigned long currentMillis = millis();
if (currentMillis - _previousMillis >= _interval)
{
_previousMillis = currentMillis;
if (_ledState == LOW)
{
_ledState = HIGH;
_interval = _offInterval;
}
else
{
_ledState = LOW;
_interval = _onInterval;
}
// set the LED with the ledState of the variable:
digitalWrite(_ledPin, _ledState);
}
}