-
Notifications
You must be signed in to change notification settings - Fork 0
/
LED.cpp
executable file
·82 lines (70 loc) · 1.56 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
||
|| @file LED.cpp
|| @version 1.1
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Provide an easy way of making LEDs
|| #
||
|| @license
|| | Copyright (c) 2009 Alexander Brevig. All rights reserved.
|| | This code is subject to AlphaLicence.txt
|| | alphabeta.alexanderbrevig.com/AlphaLicense.txt
|| #
||
*/
#include "LED.h"
LED::LED(uint8_t ledPin) {
this->pin = ledPin;
this->status = LOW;
pinMode(this->pin, OUTPUT);
}
bool LED::getState() { return status; }
void LED::on(void) {
digitalWrite(pin, HIGH);
this->status = true;
}
void LED::off(void) {
digitalWrite(pin, LOW);
this->status = false;
}
void LED::toggle(void) { status ? off() : on(); }
void LED::blink(unsigned int time, byte times) {
for (byte i = 0; i < times; i++) {
toggle();
delay(time / 2);
toggle();
delay(time / 2);
}
}
// assume PWM
void LED::setValue(byte val) {
analogWrite(pin, val);
val <= 127 ? this->status = false : this->status = true;
}
// assume PWM
void LED::fadeIn(unsigned int time) {
for (byte value = 0; value < 255; value += 5) {
analogWrite(pin, value);
delay(time / (255 / 5));
}
on();
}
// assume PWM
void LED::fadeOut(unsigned int time) {
for (byte value = 255; value > 0; value -= 5) {
analogWrite(pin, value);
delay(time / (255 / 5));
}
off();
}
extern LED DEBUG_LED(13);
/*
|| @changelog
|| | 2009-04-07 - Alexander Brevig : Altered API
|| | 2009-04-17 - Alexander Brevig : Initial Release
|| #
*/