-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb-led.cpp
89 lines (82 loc) · 1.77 KB
/
rgb-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
83
84
85
86
87
88
89
#include "rgb-led.h"
void RgbLed::setPins(uint8_t redPin, uint8_t greenPin, uint8_t bluePin) {
_redPin = redPin;
pinMode(redPin, OUTPUT);
digitalWrite(redPin, HIGH);
_greenPin = greenPin;
pinMode(greenPin, OUTPUT);
digitalWrite(greenPin, HIGH);
_bluePin = bluePin;
pinMode(bluePin, OUTPUT);
digitalWrite(bluePin, HIGH);
}
void RgbLed::turnOn(LedColor color) {
switch (color) {
case LedColor::Red:
_turnOn(_redPin);
break;
case LedColor::Green:
_turnOn(_greenPin);
break;
case LedColor::Blue:
_turnOn(_bluePin);
break;
case LedColor::Orange:
_turnOn(_redPin);
_turnOn(_greenPin);
break;
case LedColor::Purple:
_turnOn(_redPin);
_turnOn(_bluePin);
break;
case LedColor::Cyan:
_turnOn(_greenPin);
_turnOn(_bluePin);
break;
case LedColor::White:
_turnOn(_redPin);
_turnOn(_greenPin);
_turnOn(_bluePin);
break;
default:
break;
}
}
void RgbLed::turnOff(LedColor color) {
switch (color) {
case LedColor::Red:
_turnOff(_redPin);
break;
case LedColor::Green:
_turnOff(_greenPin);
break;
case LedColor::Blue:
_turnOff(_bluePin);
break;
case LedColor::Orange:
_turnOff(_redPin);
_turnOff(_greenPin);
break;
case LedColor::Purple:
_turnOff(_redPin);
_turnOff(_bluePin);
break;
case LedColor::Cyan:
_turnOff(_greenPin);
_turnOff(_bluePin);
break;
case LedColor::White:
_turnOff(_redPin);
_turnOff(_greenPin);
_turnOff(_bluePin);
break;
default:
break;
}
}
void RgbLed::_turnOn(uint8_t pin) {
digitalWrite(pin, LOW);
}
void RgbLed::_turnOff(uint8_t pin) {
digitalWrite(pin, HIGH);
}