-
Notifications
You must be signed in to change notification settings - Fork 10
/
MEODither.cpp
176 lines (161 loc) · 4.41 KB
/
MEODither.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
G35: An Arduino library for GE Color Effects G-35 holiday lights.
Copyright © 2011 The G35 Authors. Use, modification, and distribution are
subject to the BSD license as described in the accompanying LICENSE file.
By Mike Tsao <http://github.com/sowbug>.
and Mark Ortiz
and Adafruit
See README for complete attributions.
*/
#include <MEODither.h>
MEODither::MEODither(MEOG35& g35, uint8_t pattern)
: MEOLightProgram(g35, pattern), intensity_(0), pattern_(pattern), colorMain_(0), wait_(0), dithStep_(0), step_(0)
{
}
uint32_t MEODither::Do()
{
bool fourtyEight;
uint8_t stepCount;
stepCount = 1;
switch (pattern_ % 6)
{
case 0: // Red to Green to Red
fourtyEight = false;
stepCount = 2;
colorMain_ = MEODither::LineRG(step_ % 32);
break;
case 1: // Green to Blue to Green
fourtyEight = false;
stepCount = 2;
colorMain_ = MEODither::LineGB(step_ % 32);
break;
case 2: //Blue to Red to Blue
fourtyEight = false;
stepCount = 2;
colorMain_ = MEODither::LineBR(step_ % 32);
break;
case 3: // Colour wheel smooth
fourtyEight = true;
stepCount = 3;
colorMain_ = MEODither::Wheel(step_ % 48);
break;
case 4: //Colour wheel jump
fourtyEight = true;
stepCount = 11;
colorMain_ = MEODither::Wheel(step_ % 48);
break;
case 5: //Always changing
fourtyEight = true;
stepCount = 0;
colorMain_ = MEODither::Wheel(step_ % 48);
step_++;// step_++;
break;
}
// Determine highest bit needed to represent pixel index
int hiBit = 0;
int n = light_count_ - 1;
for(int bit = 1; bit < 0x8000; bit <<= 1) {
if(n & bit) hiBit = bit;
}
int bit, reverse;
//for(int i = 0; i < (hiBit << 1); i++) {
// Reverse the bits in i to create ordered dither:
reverse = 0;
for(bit = 1; bit <= hiBit; bit <<= 1) {
reverse <<= 1;
if(dithStep_ & bit) reverse |= 1;
}
g35_.fill_color(reverse, 1, MEOG35::MAX_INTENSITY, colorMain_);
delay(wait_);
//}
dithStep_++;
if (dithStep_ == (hiBit << 1))
{
dithStep_ = 0;
//pattern_++;
//reset at end of wheel or line
step_ = step_ + stepCount; //step_++; step_++; step_++; //do 4, so not so smooth
if (((step_ == 48) && fourtyEight) || ((step_ == 32) && !fourtyEight))
{
step_ = 0;
}
}
return bulb_frame_;
}
uint32_t MEODither::Wheel(uint16_t WheelPos)
{
byte r, g, b;
switch(WheelPos / 16)
{
case 0:
r = 15 - WheelPos % 16; // red down
g = WheelPos % 16; // green up
b = 0; // blue off
break;
case 1:
g = 15 - WheelPos % 16; // green down
b = WheelPos % 16; // blue up
r = 0; // red off
break;
case 2:
b = 15 - WheelPos % 16; // blue down
r = WheelPos % 16; // red up
g = 0; // green off
break;
}
return(COLOR(r,g,b));
}
uint32_t MEODither::LineRG(uint16_t WheelPos)
{
byte r, g, b;
switch(WheelPos / 16)
{
case 0:
r = 15 - WheelPos % 16; // red down
g = WheelPos % 16; // green up
b = 0; // blue off
break;
case 1:
r = WheelPos % 16; // red up
g = 15 - WheelPos % 16; // green down
b = 0; // blue off
break;
}
return(COLOR(r,g,b));
}
uint32_t MEODither::LineGB(uint16_t WheelPos)
{
byte r, g, b;
switch(WheelPos / 16)
{
case 0:
r = 0; // red off
g = 15 - WheelPos % 16; // green down
b = WheelPos % 16; // blue up
break;
case 1:
r = 0; // red off
g = WheelPos % 16; // green up
b = 15 - WheelPos % 16; // blue down
break;
}
return(COLOR(r,g,b));
}
uint32_t MEODither::LineBR(uint16_t WheelPos)
{
byte r, g, b;
switch(WheelPos / 16)
{
case 0:
r = WheelPos % 16; // red up
g = 0; // green off
b = 15 - WheelPos % 16; // blue down
break;
case 1:
r = 15 - WheelPos % 16; // red down
g = 0; // green off
b = WheelPos % 16; // blue up
break;
}
return(COLOR(r,g,b));
}