-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolor.cpp
More file actions
100 lines (86 loc) · 2.46 KB
/
color.cpp
File metadata and controls
100 lines (86 loc) · 2.46 KB
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
90
91
92
93
94
95
96
97
98
99
100
#include "color.h"
Color::Color(unsigned char pin) : Component(pin, 50), maxIntensity(255), intensity(0) {
}
Color::Color(unsigned char pin, Potentiometer & pot) : Component(pin), maxIntensity(255), intensity(0) {
intensityPot = &pot;
}
void Color::init(unsigned char mode){
Component::init(mode);
writeVal(intensity);
}
void Color::assignDelayPot(Potentiometer & pot, unsigned char scale) {
delayPot = &pot;
delayScale = scale;
}
void Color::fadeTo(unsigned char intensityFinal) {
if (intensityPot && intensityFinal > updateMaxIntensity()) {
intensityFinal = maxIntensity;
}
while (intensity != intensityFinal) {
if (cycleCheck()) {
if (intensity < intensityFinal) {
writeVal(++intensity);
} else if (intensity > intensityFinal) {
writeVal(--intensity);
}
}
updateDelay();
}
}
bool Color::stepTo(unsigned char intensityFinal) {
if (intensityPot && intensityFinal > updateMaxIntensity()) {
intensityFinal = maxIntensity;
}
if (cycleCheck()) {
if (intensity < intensityFinal) {
++intensity;
} else if (intensity > intensityFinal) {
--intensity;
}
writeVal(intensity);
updateDelay();
}
return (intensity == intensityFinal) ? false : true;
}
unsigned char Color::updateMaxIntensity() {
return maxIntensity = (intensityPot->update() / 4);
}
unsigned int Color::updateDelay() {
if (delayPot) {
return delayVal = (delayPot->update() / delayScale);
}
return delayVal;
}
int Color::operator=(unsigned char opIntensity) {
intensity = opIntensity;
writeVal(intensity);
}
int Color::operator=(Color & opColor) {
intensity = opColor.getIntensity();
}
int Color::operator+(unsigned char opIntensity) {
if (intensity < (256 - opIntensity)) {
intensity += opIntensity;
writeVal(intensity);
}
return intensity;
}
int Color::operator-(unsigned char opIntensity) {
if (intensity > (0 + opIntensity)) {
intensity -= opIntensity;
writeVal(intensity);
}
return intensity;
}
int Color::operator++() {
if (intensity < 256) {
writeVal(++intensity);
}
return intensity;
}
int Color::operator--() {
if (intensity > 0) {
writeVal(--intensity);
}
return intensity;
}