| 199 |
Kevin |
1 |
// <editor-fold defaultstate="collapsed" desc="Configuration Bits">
|
| 193 |
Kevin |
2 |
/* ------------------------------------------------------------ */
|
|
|
3 |
/* PIC32 Configuration Settings */
|
|
|
4 |
/* ------------------------------------------------------------ */
|
|
|
5 |
/* Oscillator Settings */
|
|
|
6 |
#pragma config FNOSC = PRIPLL // Oscillator Selection Bits
|
|
|
7 |
#pragma config POSCMOD = EC // Primary Oscillator Configuration
|
|
|
8 |
#pragma config FPLLIDIV = DIV_2 // PLL Input Divider
|
|
|
9 |
#pragma config FPLLMUL = MUL_20 // PLL Multiplier
|
|
|
10 |
#pragma config FPLLODIV = DIV_1 // PLL Output Divider
|
| 199 |
Kevin |
11 |
#pragma config FPBDIV = DIV_1 // Peripheral Clock Divisor (timers/UART/SPI/I2C)
|
| 193 |
Kevin |
12 |
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable
|
|
|
13 |
/* Clock Control Settings */
|
|
|
14 |
#pragma config IESO = OFF // Internal/External Clock Switch Over
|
|
|
15 |
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection
|
|
|
16 |
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin
|
|
|
17 |
/* USB Settings */
|
|
|
18 |
#pragma config UPLLEN = ON // USB PLL Enable
|
|
|
19 |
#pragma config UPLLIDIV = DIV_2 // USB PLL Input Divider
|
|
|
20 |
#pragma config FVBUSONIO = OFF // USB VBUS ON Selection
|
|
|
21 |
#pragma config FUSBIDIO = OFF // USB USID Selection
|
|
|
22 |
/* Other Peripheral Device Settings */
|
|
|
23 |
#pragma config FWDTEN = OFF // Watchdog Timer Enable
|
|
|
24 |
#pragma config WDTPS = PS1024 // Watchdog Timer Postscaler
|
|
|
25 |
#pragma config FSRSSEL = PRIORITY_7 // SRS Interrupt Priority
|
|
|
26 |
#pragma config FCANIO = OFF // CAN I/O Pin Select (default/alternate)
|
|
|
27 |
#pragma config FETHIO = ON // Ethernet I/O Pin Select (default/alternate)
|
|
|
28 |
#pragma config FMIIEN = OFF // Ethernet MII/RMII select (OFF=RMII)
|
|
|
29 |
/* Code Protection Settings */
|
|
|
30 |
#pragma config CP = OFF // Code Protect
|
|
|
31 |
#pragma config BWP = OFF // Boot Flash Write Protect
|
|
|
32 |
#pragma config PWP = OFF // Program Flash Write Protect
|
|
|
33 |
/* Debug Settings */
|
|
|
34 |
#pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select (on-board debugger)
|
|
|
35 |
/* ------------------------------------------------------------ */
|
| 199 |
Kevin |
36 |
// </editor-fold>
|
| 193 |
Kevin |
37 |
|
|
|
38 |
#include <xc.h>
|
|
|
39 |
#include <plib.h>
|
| 199 |
Kevin |
40 |
#include <stdlib.h>
|
| 193 |
Kevin |
41 |
#include "defines.h"
|
| 199 |
Kevin |
42 |
#include "SPI1.h"
|
| 206 |
Kevin |
43 |
#include "TIMER4.h"
|
| 199 |
Kevin |
44 |
#include "TIMER5.h"
|
|
|
45 |
#include "CUBE.h"
|
| 200 |
Kevin |
46 |
#include "BTN.h"
|
| 193 |
Kevin |
47 |
|
| 200 |
Kevin |
48 |
void BTN1_Interrupt(void);
|
|
|
49 |
void BTN2_Interrupt(void);
|
| 206 |
Kevin |
50 |
void BTN3_Interrupt(void);
|
| 199 |
Kevin |
51 |
void Animation_Solid_Colors(int iterations, int delay_ms);
|
|
|
52 |
void Animation_Layer_Alternate(int iterations, int delay_ms);
|
|
|
53 |
void Animation_Pixel_Alternate(int iterations, int delay_ms);
|
|
|
54 |
void Animation_Full_Color_Sweep(int iterations, int delay_us);
|
|
|
55 |
void Animation_Row_Column_Sweep(int iterations, int delay_ms);
|
|
|
56 |
void Animation_Pixel_Sweep(int iterations, int delay_ms);
|
|
|
57 |
void Animation_Pseudo_Random_Colors(int iterations,int delay_ms);
|
|
|
58 |
void Animation_Random_Colors(int iterations, int delay_ms);
|
|
|
59 |
void Animation_Cube_In_Cube(int iterations, int delay_ms);
|
| 205 |
Kevin |
60 |
void Animation_Double_Rotation(int iterations, int delay_ms);
|
| 199 |
Kevin |
61 |
|
|
|
62 |
void Delay_MS(unsigned int delay_ms) {
|
| 201 |
Kevin |
63 |
// Delays the CPU for the given amount of time.
|
|
|
64 |
// Note: Watch out for integer overflow! (max delay_ms = 107374) ??
|
| 199 |
Kevin |
65 |
unsigned int delay = delay_ms * MS_TO_CT_TICKS;
|
|
|
66 |
unsigned int startTime = ReadCoreTimer();
|
|
|
67 |
while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
void Delay_US(unsigned int delay_us) {
|
| 201 |
Kevin |
71 |
// Delays the CPU for the given amount of time.
|
|
|
72 |
// Note: Watch out for integer overflow!
|
| 199 |
Kevin |
73 |
unsigned int delay = delay_us * US_TO_CT_TICKS;
|
|
|
74 |
unsigned int startTime = ReadCoreTimer();
|
|
|
75 |
while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
|
|
|
76 |
}
|
|
|
77 |
|
| 193 |
Kevin |
78 |
int main() {
|
|
|
79 |
/* Configure the target for maximum performance at 80 MHz. */
|
| 199 |
Kevin |
80 |
// Note: This overrides the peripheral clock to 80Mhz regardless of config
|
|
|
81 |
SYSTEMConfigPerformance(CPU_CLOCK_HZ);
|
| 193 |
Kevin |
82 |
|
| 199 |
Kevin |
83 |
// Configure the interrupts for multiple vectors
|
| 193 |
Kevin |
84 |
INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
|
|
|
85 |
|
| 199 |
Kevin |
86 |
// Set all analog I/O pins to digital
|
|
|
87 |
AD1PCFGSET = 0xFFFF;
|
| 193 |
Kevin |
88 |
|
| 201 |
Kevin |
89 |
// Initialize peripherals
|
| 199 |
Kevin |
90 |
SPI1_DATA spi_data;
|
|
|
91 |
SPI1_Init(&spi_data);
|
|
|
92 |
|
|
|
93 |
PWM2_Init();
|
|
|
94 |
PWM2_Start();
|
|
|
95 |
|
|
|
96 |
CUBE_DATA cube_data;
|
| 206 |
Kevin |
97 |
Cube_Init(&cube_data, 0x40);
|
| 199 |
Kevin |
98 |
|
|
|
99 |
// 2083 = 60Hz, 500 = 250Hz, 250 = 500Hz
|
| 206 |
Kevin |
100 |
TIMER5_DATA timer_5_data;
|
|
|
101 |
TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
|
| 199 |
Kevin |
102 |
TIMER5_Start();
|
|
|
103 |
|
| 206 |
Kevin |
104 |
TIMER4_DATA timer_4_data;
|
|
|
105 |
TIMER4_Init(&timer_4_data, &Cube_Text_Interrupt, 150000);
|
|
|
106 |
TIMER4_Start();
|
|
|
107 |
|
| 201 |
Kevin |
108 |
BTN_DATA btn_data;
|
|
|
109 |
BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
|
| 205 |
Kevin |
110 |
|
| 201 |
Kevin |
111 |
// Begin display
|
| 206 |
Kevin |
112 |
// Cube_Set_All(0xFF,0xFF,0xFF);
|
|
|
113 |
// Delay_MS(6000);
|
|
|
114 |
// Cube_Set_All(0xFF,0,0);
|
|
|
115 |
// Delay_MS(6000);
|
|
|
116 |
// Cube_Set_All(0,0xFF,0);
|
|
|
117 |
// Delay_MS(6000);
|
|
|
118 |
// Cube_Set_All(0,0,0xFF);
|
|
|
119 |
// Delay_MS(6000);
|
| 200 |
Kevin |
120 |
|
| 206 |
Kevin |
121 |
// Set the overlay text
|
|
|
122 |
char text_string[] = "CCMLab ";
|
|
|
123 |
Cube_Text_Init(text_string, 7, 0xFF, 0xFF, 0xFF);
|
|
|
124 |
|
| 199 |
Kevin |
125 |
// Loop through some preset animations
|
|
|
126 |
while(1) {
|
|
|
127 |
Animation_Solid_Colors(2,300);
|
|
|
128 |
Animation_Layer_Alternate(2,300);
|
|
|
129 |
Animation_Pixel_Alternate(1,200);
|
|
|
130 |
Animation_Full_Color_Sweep(2,1000);
|
|
|
131 |
Animation_Row_Column_Sweep(2,40);
|
|
|
132 |
Animation_Pseudo_Random_Colors(10,300);
|
|
|
133 |
Animation_Random_Colors(10,300);
|
|
|
134 |
Animation_Cube_In_Cube(4,300);
|
| 205 |
Kevin |
135 |
Animation_Double_Rotation(2,40);
|
| 199 |
Kevin |
136 |
}
|
| 193 |
Kevin |
137 |
}
|
|
|
138 |
|
| 200 |
Kevin |
139 |
// Function call on button 1 press to change refresh rate
|
|
|
140 |
void BTN1_Interrupt(void) {
|
|
|
141 |
static char state;
|
| 206 |
Kevin |
142 |
state = (state == 4) ? 0 : state + 1;
|
| 200 |
Kevin |
143 |
TIMER5_Stop();
|
|
|
144 |
switch (state) {
|
|
|
145 |
case 0:
|
| 201 |
Kevin |
146 |
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500);
|
| 200 |
Kevin |
147 |
break;
|
|
|
148 |
case 1:
|
| 201 |
Kevin |
149 |
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2083);
|
| 200 |
Kevin |
150 |
break;
|
|
|
151 |
case 2:
|
| 201 |
Kevin |
152 |
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 4166);
|
| 200 |
Kevin |
153 |
break;
|
|
|
154 |
case 3:
|
| 201 |
Kevin |
155 |
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 13107);
|
| 200 |
Kevin |
156 |
break;
|
| 206 |
Kevin |
157 |
case 4:
|
|
|
158 |
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 200000);
|
|
|
159 |
break;
|
| 200 |
Kevin |
160 |
}
|
|
|
161 |
TIMER5_Start();
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
// Function call on button 2 press to change brightness
|
|
|
165 |
void BTN2_Interrupt(void) {
|
|
|
166 |
static char state;
|
| 205 |
Kevin |
167 |
state = (state == 6) ? 0 : state + 1;
|
| 200 |
Kevin |
168 |
TIMER5_Stop();
|
| 206 |
Kevin |
169 |
TIMER4_Stop();
|
| 200 |
Kevin |
170 |
Delay_MS(1); // Need to wait for all SPI writes to complete
|
|
|
171 |
char BC;
|
|
|
172 |
switch (state) {
|
|
|
173 |
case 0:
|
|
|
174 |
BC = 0x01;
|
|
|
175 |
break;
|
|
|
176 |
case 1:
|
|
|
177 |
BC = 0x08;
|
|
|
178 |
break;
|
|
|
179 |
case 2:
|
|
|
180 |
BC = 0x10;
|
|
|
181 |
break;
|
|
|
182 |
case 3:
|
|
|
183 |
BC = 0x20;
|
|
|
184 |
break;
|
|
|
185 |
case 4:
|
|
|
186 |
BC = 0x40;
|
|
|
187 |
break;
|
|
|
188 |
case 5:
|
| 205 |
Kevin |
189 |
BC = 0x80;
|
| 200 |
Kevin |
190 |
break;
|
| 205 |
Kevin |
191 |
case 6:
|
|
|
192 |
BC = 0xFF;
|
|
|
193 |
break;
|
| 200 |
Kevin |
194 |
}
|
|
|
195 |
Cube_Write_DCS(BC);
|
|
|
196 |
TIMER5_Start();
|
| 206 |
Kevin |
197 |
TIMER4_Start();
|
| 200 |
Kevin |
198 |
}
|
|
|
199 |
|
| 206 |
Kevin |
200 |
// Function call on button 3 press to change text scroll speed
|
|
|
201 |
void BTN3_Interrupt(void) {
|
|
|
202 |
static char state;
|
|
|
203 |
state = (state == 4) ? 0 : state + 1;
|
|
|
204 |
TIMER4_Stop();
|
|
|
205 |
switch (state) {
|
|
|
206 |
case 0:
|
|
|
207 |
TIMER4_Init(NULL, &Cube_Text_Interrupt, 209712);
|
|
|
208 |
break;
|
|
|
209 |
case 1:
|
|
|
210 |
TIMER4_Init(NULL, &Cube_Text_Interrupt, 180000);
|
|
|
211 |
break;
|
|
|
212 |
case 2:
|
|
|
213 |
TIMER4_Init(NULL, &Cube_Text_Interrupt, 150000);
|
|
|
214 |
break;
|
|
|
215 |
case 3:
|
|
|
216 |
TIMER4_Init(NULL, &Cube_Text_Interrupt, 100000);
|
|
|
217 |
break;
|
|
|
218 |
case 4:
|
|
|
219 |
TIMER4_Init(NULL, &Cube_Text_Interrupt, 10000);
|
|
|
220 |
break;
|
|
|
221 |
}
|
|
|
222 |
TIMER4_Start();
|
|
|
223 |
}
|
|
|
224 |
|
| 199 |
Kevin |
225 |
void Animation_Solid_Colors(int iterations, int delay_ms) {
|
|
|
226 |
int i;
|
|
|
227 |
for (i = 0; i < iterations; i++) {
|
|
|
228 |
Cube_Set_All(RED);
|
|
|
229 |
Delay_MS(delay_ms);
|
|
|
230 |
Cube_Set_All(GREEN);
|
|
|
231 |
Delay_MS(delay_ms);
|
|
|
232 |
Cube_Set_All(BLUE);
|
|
|
233 |
Delay_MS(delay_ms);
|
|
|
234 |
}
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
void Animation_Layer_Alternate(int iterations, int delay_ms) {
|
|
|
238 |
int i,z;
|
|
|
239 |
for (z = 0; z < iterations; z++) {
|
|
|
240 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
241 |
if (i % 3 == 0)
|
|
|
242 |
Cube_Set_Layer(i,RED);
|
|
|
243 |
else if (i % 3 == 1)
|
|
|
244 |
Cube_Set_Layer(i,GREEN);
|
|
|
245 |
else
|
|
|
246 |
Cube_Set_Layer(i,BLUE);
|
|
|
247 |
}
|
|
|
248 |
Delay_MS(delay_ms);
|
|
|
249 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
250 |
if (i % 3 == 0)
|
|
|
251 |
Cube_Set_Layer(i,GREEN);
|
|
|
252 |
else if (i % 3 == 1)
|
|
|
253 |
Cube_Set_Layer(i,BLUE);
|
|
|
254 |
else
|
|
|
255 |
Cube_Set_Layer(i,RED);
|
|
|
256 |
}
|
|
|
257 |
Delay_MS(delay_ms);
|
|
|
258 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
259 |
if (i % 3 == 0)
|
|
|
260 |
Cube_Set_Layer(i,BLUE);
|
|
|
261 |
else if (i % 3 == 1)
|
|
|
262 |
Cube_Set_Layer(i,RED);
|
|
|
263 |
else
|
|
|
264 |
Cube_Set_Layer(i,GREEN);
|
|
|
265 |
}
|
|
|
266 |
Delay_MS(delay_ms);
|
|
|
267 |
}
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
void Animation_Pixel_Alternate(int iterations, int delay_ms) {
|
|
|
271 |
int i,j,k,z;
|
|
|
272 |
for (z = 0; z < iterations; z++) {
|
|
|
273 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
274 |
Cube_Clear();
|
|
|
275 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
276 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
|
|
|
277 |
int var = (j * 8) + k;
|
|
|
278 |
if (var % 3 == 0)
|
|
|
279 |
Cube_Set_Pixel(i,j,k,RED);
|
|
|
280 |
else if (var % 3 == 1)
|
|
|
281 |
Cube_Set_Pixel(i,j,k,GREEN);
|
|
|
282 |
else
|
|
|
283 |
Cube_Set_Pixel(i,j,k,BLUE);
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
Delay_MS(delay_ms);
|
|
|
287 |
Cube_Clear();
|
|
|
288 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
289 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
|
|
|
290 |
int var = (j * 8) + k;
|
|
|
291 |
if (var % 3 == 0)
|
|
|
292 |
Cube_Set_Pixel(i,j,k,GREEN);
|
|
|
293 |
else if (var % 3 == 1)
|
|
|
294 |
Cube_Set_Pixel(i,j,k,BLUE);
|
|
|
295 |
else
|
|
|
296 |
Cube_Set_Pixel(i,j,k,RED);
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
Delay_MS(delay_ms);
|
|
|
300 |
Cube_Clear();
|
|
|
301 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
302 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
|
|
|
303 |
int var = (j * 8) + k;
|
|
|
304 |
if (var % 3 == 0)
|
|
|
305 |
Cube_Set_Pixel(i,j,k,BLUE);
|
|
|
306 |
else if (var % 3 == 1)
|
|
|
307 |
Cube_Set_Pixel(i,j,k,RED);
|
|
|
308 |
else
|
|
|
309 |
Cube_Set_Pixel(i,j,k,GREEN);
|
|
|
310 |
}
|
|
|
311 |
}
|
|
|
312 |
Delay_MS(delay_ms);
|
|
|
313 |
}
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
void Animation_Full_Color_Sweep(int iterations, int delay_us) {
|
|
|
318 |
int i,z;
|
|
|
319 |
for (z = 0; z < iterations; z++) {
|
|
|
320 |
for (i = 0; i < 0x0FF; i+=2) {
|
|
|
321 |
Cube_Set_All(i,0,0);
|
|
|
322 |
Delay_US(delay_us);
|
|
|
323 |
}
|
|
|
324 |
for (i = 0; i < 0x0FF; i+=2) {
|
|
|
325 |
Cube_Set_All(0x0FF,i,0);
|
|
|
326 |
Delay_US(delay_us);
|
|
|
327 |
}
|
|
|
328 |
for (i = 0x0FF; i >= 0; i-=2) {
|
|
|
329 |
Cube_Set_All(i,0x0FF,0);
|
|
|
330 |
Delay_US(delay_us);
|
|
|
331 |
}
|
|
|
332 |
for (i = 0; i < 0x0FF; i+=2) {
|
|
|
333 |
Cube_Set_All(0,0x0FF,i);
|
|
|
334 |
Delay_US(delay_us);
|
|
|
335 |
}
|
|
|
336 |
for (i = 0; i < 0x0FF; i+=2) {
|
|
|
337 |
Cube_Set_All(i,0x0FF,0x0FF);
|
|
|
338 |
Delay_US(delay_us);
|
|
|
339 |
}
|
|
|
340 |
for (i = 0x0FF; i >= 0; i-=2) {
|
|
|
341 |
Cube_Set_All(0x0FF,i,0x0FF);
|
|
|
342 |
Delay_US(delay_us);
|
|
|
343 |
}
|
|
|
344 |
for (i = 0x0FF; i >= 0; i-=2) {
|
|
|
345 |
Cube_Set_All(i,0,0x0FF);
|
|
|
346 |
Delay_US(delay_us);
|
|
|
347 |
}
|
|
|
348 |
for (i = 0x100; i >= 0; i-=2) {
|
|
|
349 |
Cube_Set_All(0,0,i);
|
|
|
350 |
Delay_US(delay_us);
|
|
|
351 |
}
|
|
|
352 |
}
|
|
|
353 |
}
|
|
|
354 |
|
|
|
355 |
void Animation_Row_Column_Sweep(int iterations, int delay_ms) {
|
|
|
356 |
int i,j,k,a,z;
|
|
|
357 |
for (z = 0; z < iterations; z++) {
|
|
|
358 |
for (i = 0; i < 3; i++) {
|
|
|
359 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
360 |
Cube_Clear();
|
|
|
361 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++)
|
|
|
362 |
if (i % 3 == 0)
|
|
|
363 |
for (a = 0; a < CUBE_LAYER_COUNT; a++)
|
|
|
364 |
Cube_Set_Pixel(a,j,k,RED);
|
|
|
365 |
else if (i % 3 == 1)
|
|
|
366 |
for (a = 0; a < CUBE_LAYER_COUNT; a++)
|
|
|
367 |
Cube_Set_Pixel(a,j,k,GREEN);
|
|
|
368 |
else
|
|
|
369 |
for (a = 0; a < CUBE_LAYER_COUNT; a++)
|
|
|
370 |
Cube_Set_Pixel(a,j,k,BLUE);
|
|
|
371 |
Delay_MS(delay_ms);
|
|
|
372 |
}
|
|
|
373 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
374 |
Cube_Clear();
|
|
|
375 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++)
|
|
|
376 |
if (i % 3 == 0)
|
|
|
377 |
for (a = 0; a < CUBE_LAYER_COUNT; a++)
|
|
|
378 |
Cube_Set_Pixel(a,k,j,RED);
|
|
|
379 |
else if (i % 3 == 1)
|
|
|
380 |
for (a = 0; a < CUBE_LAYER_COUNT; a++)
|
|
|
381 |
Cube_Set_Pixel(a,k,j,GREEN);
|
|
|
382 |
else
|
|
|
383 |
for (a = 0; a < CUBE_LAYER_COUNT; a++)
|
|
|
384 |
Cube_Set_Pixel(a,k,j,BLUE);
|
|
|
385 |
Delay_MS(delay_ms);
|
|
|
386 |
}
|
|
|
387 |
for (j = CUBE_LAYER_COUNT-1; j >= 0; j--) {
|
|
|
388 |
Cube_Clear();
|
|
|
389 |
if (i % 3 == 0) {
|
|
|
390 |
for (k = 0; k < CUBE_LAYER_COUNT; k++)
|
|
|
391 |
if (k == j)
|
|
|
392 |
Cube_Set_Layer(k,RED);
|
|
|
393 |
} else if (i % 3 == 1) {
|
|
|
394 |
for (k = 0; k < CUBE_LAYER_COUNT; k++)
|
|
|
395 |
if (k == j)
|
|
|
396 |
Cube_Set_Layer(k,GREEN);
|
|
|
397 |
} else {
|
|
|
398 |
for (k = 0; k < CUBE_LAYER_COUNT; k++)
|
|
|
399 |
if (k == j)
|
|
|
400 |
Cube_Set_Layer(k,BLUE);
|
|
|
401 |
}
|
|
|
402 |
Delay_MS(delay_ms);
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
}
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
void Animation_Pixel_Sweep(int iterations, int delay_ms) {
|
|
|
409 |
int i,j,k,z,a;
|
|
|
410 |
for (z = 0; z < iterations; z++) {
|
|
|
411 |
for (a = 0; a < 3; a++) {
|
|
|
412 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
413 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
414 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
|
|
|
415 |
Cube_Clear();
|
|
|
416 |
if (a % 3 == 0) {
|
|
|
417 |
Cube_Set_Pixel(i,j,k,RED);
|
|
|
418 |
} else if (a % 3 == 1) {
|
|
|
419 |
Cube_Set_Pixel(i,j,k,GREEN);
|
|
|
420 |
} else {
|
|
|
421 |
Cube_Set_Pixel(i,j,k,BLUE);
|
|
|
422 |
}
|
|
|
423 |
Delay_MS(delay_ms);
|
|
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
}
|
|
|
427 |
}
|
|
|
428 |
}
|
|
|
429 |
}
|
|
|
430 |
|
|
|
431 |
void Animation_Pseudo_Random_Colors(int iterations, int delay_ms) {
|
|
|
432 |
int i,j,k,z;
|
|
|
433 |
for (z = 0; z < iterations; z++) {
|
|
|
434 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
435 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
436 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
|
|
|
437 |
unsigned int a = rand();
|
|
|
438 |
if (a % 5 == 0)
|
|
|
439 |
Cube_Set_Pixel(i,j,k,RED);
|
|
|
440 |
else if (a % 5 == 1)
|
|
|
441 |
Cube_Set_Pixel(i,j,k,GREEN);
|
|
|
442 |
else if (a % 5 == 2)
|
|
|
443 |
Cube_Set_Pixel(i,j,k,BLUE);
|
|
|
444 |
else if (a % 5 == 3)
|
|
|
445 |
Cube_Set_Pixel(i,j,k,PURPLE);
|
|
|
446 |
else if (a % 5 == 4)
|
|
|
447 |
Cube_Set_Pixel(i,j,k,YELLOW);
|
|
|
448 |
else
|
|
|
449 |
Cube_Set_Pixel(i,j,k,ORANGE);
|
|
|
450 |
}
|
|
|
451 |
}
|
|
|
452 |
}
|
|
|
453 |
Delay_MS(delay_ms);
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
|
|
|
457 |
void Animation_Random_Colors(int iterations, int delay_ms) {
|
|
|
458 |
int i,j,k,z;
|
|
|
459 |
for (z = 0; z < iterations; z++) {
|
|
|
460 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
461 |
for (j = 0; j < CUBE_ROW_COUNT; j++) {
|
|
|
462 |
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
|
|
|
463 |
Cube_Set_Pixel(i,j,k,rand()&0x0FF,rand()&0x0FF,rand()&0x0FF);
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
}
|
|
|
467 |
Delay_MS(delay_ms);
|
|
|
468 |
}
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
void Animation_Cube_In_Cube(int iterations, int delay_ms) {
|
|
|
472 |
int z,x,i,j,k;
|
|
|
473 |
for (z = 0; z < iterations; z++) {
|
|
|
474 |
for (x = 0; x < 5; x++) {
|
|
|
475 |
Cube_Clear();
|
|
|
476 |
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
|
|
|
477 |
if ((x == 0 || x == 4)&&(i == 0 || i == 7)) {
|
|
|
478 |
Cube_Set_Layer(i,RED);
|
|
|
479 |
} else if ((x == 1 || x == 4)&&(i == 1 || i == 6)) {
|
|
|
480 |
for (j = 1; j < CUBE_ROW_COUNT-1; j++)
|
|
|
481 |
for (k = 1; k < CUBE_COLUMN_COUNT-1; k++)
|
|
|
482 |
Cube_Set_Pixel(i,j,k,YELLOW);
|
|
|
483 |
} else if ((x == 2 || x == 4)&&(i == 2 || i == 5)) {
|
|
|
484 |
for (j = 2; j < CUBE_ROW_COUNT-2; j++)
|
|
|
485 |
for (k = 2; k < CUBE_COLUMN_COUNT-2; k++)
|
|
|
486 |
Cube_Set_Pixel(i,j,k,GREEN);
|
|
|
487 |
} else if ((x == 3 || x == 4)&&(i == 3 || i == 4)) {
|
|
|
488 |
for (j = 3; j < CUBE_ROW_COUNT-3; j++)
|
|
|
489 |
for (k = 3; k < CUBE_COLUMN_COUNT-3; k++)
|
|
|
490 |
Cube_Set_Pixel(i,j,k,BLUE);
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
if ((x == 0 || x == 4)&&(i > 0 && i < 8)) {
|
|
|
494 |
for (j = 0; j < 8; j++) {
|
|
|
495 |
Cube_Set_Pixel(i,j,0,RED);
|
|
|
496 |
Cube_Set_Pixel(i,j,7,RED);
|
|
|
497 |
Cube_Set_Pixel(i,0,j,RED);
|
|
|
498 |
Cube_Set_Pixel(i,7,j,RED);
|
|
|
499 |
}
|
|
|
500 |
}
|
|
|
501 |
if ((x == 1 || x == 4)&&(i > 1 && i < 7)) {
|
|
|
502 |
for (j = 1; j < 7; j++) {
|
|
|
503 |
Cube_Set_Pixel(i,j,1,YELLOW);
|
|
|
504 |
Cube_Set_Pixel(i,j,6,YELLOW);
|
|
|
505 |
Cube_Set_Pixel(i,1,j,YELLOW);
|
|
|
506 |
Cube_Set_Pixel(i,6,j,YELLOW);
|
|
|
507 |
}
|
|
|
508 |
}
|
|
|
509 |
if ((x == 2 || x == 4)&&(i > 2 && i < 6)) {
|
|
|
510 |
for (j = 2; j < 6; j++) {
|
|
|
511 |
Cube_Set_Pixel(i,j,2,GREEN);
|
|
|
512 |
Cube_Set_Pixel(i,j,5,GREEN);
|
|
|
513 |
Cube_Set_Pixel(i,2,j,GREEN);
|
|
|
514 |
Cube_Set_Pixel(i,5,j,GREEN);
|
|
|
515 |
}
|
|
|
516 |
}
|
|
|
517 |
}
|
|
|
518 |
Delay_MS(delay_ms);
|
|
|
519 |
}
|
|
|
520 |
}
|
| 205 |
Kevin |
521 |
}
|
|
|
522 |
|
|
|
523 |
void Animation_Double_Rotation(int iterations, int delay_ms) {
|
|
|
524 |
Cube_Clear();
|
|
|
525 |
int i,x,y,z;
|
|
|
526 |
for (z = 0; z < 3; z++) {
|
|
|
527 |
switch (z % 3) {
|
|
|
528 |
case 0:
|
|
|
529 |
for (y = 0; y < CUBE_LAYER_COUNT; y++) {
|
|
|
530 |
Cube_Set_Pixel(y, 0, 0, 0xFF, 0x00, 0x00);
|
|
|
531 |
Cube_Set_Pixel(y, 1, 1, 0xFF, 0x00, 0x00);
|
|
|
532 |
Cube_Set_Pixel(y, 2, 2, 0xFF, 0x00, 0x00);
|
|
|
533 |
Cube_Set_Pixel(y, 3, 3, 0xFF, 0x00, 0x00);
|
|
|
534 |
Cube_Set_Pixel(y, 4, 4, 0xFF, 0x00, 0x00);
|
|
|
535 |
Cube_Set_Pixel(y, 5, 5, 0xFF, 0x00, 0x00);
|
|
|
536 |
Cube_Set_Pixel(y, 6, 6, 0xFF, 0x00, 0x00);
|
|
|
537 |
Cube_Set_Pixel(y, 7, 7, 0xFF, 0x00, 0x00);
|
|
|
538 |
}
|
|
|
539 |
break;
|
|
|
540 |
case 1:
|
|
|
541 |
for (y = 0; y < CUBE_LAYER_COUNT; y++) {
|
|
|
542 |
Cube_Set_Pixel(y, 0, 0, 0x00, 0xFF, 0x00);
|
|
|
543 |
Cube_Set_Pixel(y, 1, 1, 0x00, 0xFF, 0x00);
|
|
|
544 |
Cube_Set_Pixel(y, 2, 2, 0x00, 0xFF, 0x00);
|
|
|
545 |
Cube_Set_Pixel(y, 3, 3, 0x00, 0xFF, 0x00);
|
|
|
546 |
Cube_Set_Pixel(y, 4, 4, 0x00, 0xFF, 0x00);
|
|
|
547 |
Cube_Set_Pixel(y, 5, 5, 0x00, 0xFF, 0x00);
|
|
|
548 |
Cube_Set_Pixel(y, 6, 6, 0x00, 0xFF, 0x00);
|
|
|
549 |
Cube_Set_Pixel(y, 7, 7, 0x00, 0xFF, 0x00);
|
|
|
550 |
}
|
|
|
551 |
break;
|
|
|
552 |
case 2:
|
|
|
553 |
for (y = 0; y < CUBE_LAYER_COUNT; y++) {
|
|
|
554 |
Cube_Set_Pixel(y, 0, 0, 0x00, 0x00, 0xFF);
|
|
|
555 |
Cube_Set_Pixel(y, 1, 1, 0x00, 0x00, 0xFF);
|
|
|
556 |
Cube_Set_Pixel(y, 2, 2, 0x00, 0x00, 0xFF);
|
|
|
557 |
Cube_Set_Pixel(y, 3, 3, 0x00, 0x00, 0xFF);
|
|
|
558 |
Cube_Set_Pixel(y, 4, 4, 0x00, 0x00, 0xFF);
|
|
|
559 |
Cube_Set_Pixel(y, 5, 5, 0x00, 0x00, 0xFF);
|
|
|
560 |
Cube_Set_Pixel(y, 6, 6, 0x00, 0x00, 0xFF);
|
|
|
561 |
Cube_Set_Pixel(y, 7, 7, 0x00, 0x00, 0xFF);
|
|
|
562 |
}
|
|
|
563 |
break;
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
for (i = 0; i < iterations; i++) {
|
|
|
567 |
for (x = 0; x < 28; x++) {
|
|
|
568 |
Delay_MS(delay_ms);
|
| 206 |
Kevin |
569 |
Cube_Rotate(0);
|
| 205 |
Kevin |
570 |
}
|
|
|
571 |
}
|
|
|
572 |
}
|
| 199 |
Kevin |
573 |
}
|