-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadLED.cpp
53 lines (40 loc) · 888 Bytes
/
RadLED.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
#include <Arduino.h>
#include <RadLED.h>
RadLED::RadLED(int pin) {
_pin = pin;
_init();
}
RadLED::RadLED() {
_pin = _internal_pin;
_init();
}
void RadLED::_init() {
pinMode(_pin, OUTPUT);
// The internal LED on my devices is the opposite, HIGH for off, LOW for on
if (_pin == _internal_pin) {
_high = LOW;
_low = HIGH;
}
else {
_high = HIGH;
_low = LOW;
}
digitalWrite(_pin, _low);
}
void RadLED::on() {
digitalWrite(_pin, _high);
}
void RadLED::off() {
digitalWrite(_pin, _low);
}
void RadLED::flash(int no_times, int on_ms, int off_ms) {
for (int count=0; count < no_times; count++) {
on();
delay(on_ms);
off();
// No point locking up the system to wait for it to be off.
if (count < no_times - 1) {
delay(off_ms);
}
}
}