/
rainbowWheel.cpp
167 lines (104 loc) · 2.48 KB
/
rainbowWheel.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
#include "rainbowWheel.hpp"
#include <stdio.h>
RainbowWheel::RainbowWheel() {
for(int i = 0; i < sideHeight; i++) {
wings[i] = 0; //Set all side lights to off
}
direction = 1; //Load
directionChange = 0;
picture_1.delay = 50000;
}
const Frame* RainbowWheel::getNextFrame() {
if(directionChange == 1) {
direction = direction*(-1); //Flip direction sign
directionChange = 0;
}
if(direction == 1) { //Rainbow "Load"
bool wedgeShift = 0;
for(int i = sideHeight - 1; i > 0; i--) {
if(wings[i] == 1 && wings[i-1] == 0) {
//If room to shift a wedge
wings[i] = 0;
wings[i-1] = 1;
wedgeShift = 1;
break;
}
}
if (wedgeShift == 0) { //If no shift, then new wedge
wings[sideHeight - 1] = 1;
if(wings[6] == 1 && wings[5] == 1) {
//If full, then start unloading next pass
directionChange = 1;
}
}
}
if(direction == -1) { //Rainbow "Unload"
if (wings[sideHeight - 1] == 1) {
wings[sideHeight - 1] = 0;
//If no shift, but top wedge is lit, remove
if(wings[0] == 0) {
//If no more wedges to remove, then load next pass
directionChange = 1;
}
}
else {
for(int i = sideHeight - 1; i > 0; i--) {
if(wings[i] == 0 && wings[i-1] == 1) {
//If room to shift a wedge
wings[i] = 1;
wings[i-1] = 0;
break;
}
}
}
}
if(wings[0] == 1) {
for(int i = 0; i < sideLength; i++) {
picture_1.m_side[i][0].r = 255;
}
}
if(wings[1] == 1) {
for(int i = 0; i < sideLength; i++) {
picture_1.m_side[i][1].r = 255;
picture_1.m_side[i][1].g = 127;
}
}
if(wings[2] == 1) {
for(int i = 0; i < sideLength; i++) {
picture_1.m_side[i][2].r = 255;
picture_1.m_side[i][2].g = 255;
}
}
if(wings[3] == 1) {
for(int i = 0; i < sideLength; i++) {
picture_1.m_side[i][3].g = 255;
}
}
if(wings[4] == 1) {
for(int i = 0; i < sideLength; i++) {
picture_1.m_side[i][4].b = 255;
}
}
if(wings[5] == 1) {
for(int i = 0; i < sideLength; i++) {
picture_1.m_side[i][5].r = 75;
picture_1.m_side[i][5].b = 130;
}
}
if(wings[6] == 1) {
for(int i = 0; i < sideLength; i++) {
picture_1.m_side[i][6].r = 143;
picture_1.m_side[i][6].b = 255;
}
}
for(int i = 0; i < sideHeight; i++) { //Check for lines to be turned off
if(wings[i] == 0) {
for(int j = 0; j < sideLength; j++) {
picture_1.m_side[j][i].r = 0;
picture_1.m_side[j][i].g = 0;
picture_1.m_side[j][i].b = 0;
}
}
}
return &picture_1;
}