Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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"
212 Kevin 42
#include "UART1.h"
199 Kevin 43
#include "SPI1.h"
206 Kevin 44
#include "TIMER4.h"
199 Kevin 45
#include "TIMER5.h"
46
#include "CUBE.h"
200 Kevin 47
#include "BTN.h"
193 Kevin 48
 
200 Kevin 49
void BTN1_Interrupt(void);
50
void BTN2_Interrupt(void);
206 Kevin 51
void BTN3_Interrupt(void);
199 Kevin 52
void Animation_Solid_Colors(int iterations, int delay_ms);
53
void Animation_Layer_Alternate(int iterations, int delay_ms);
54
void Animation_Pixel_Alternate(int iterations, int delay_ms);
55
void Animation_Full_Color_Sweep(int iterations, int delay_us);
56
void Animation_Row_Column_Sweep(int iterations, int delay_ms);
57
void Animation_Pixel_Sweep(int iterations, int delay_ms);
58
void Animation_Pseudo_Random_Colors(int iterations,int delay_ms);
59
void Animation_Random_Colors(int iterations, int delay_ms);
60
void Animation_Cube_In_Cube(int iterations, int delay_ms);
205 Kevin 61
void Animation_Double_Rotation(int iterations, int delay_ms);
199 Kevin 62
 
63
void Delay_MS(unsigned int delay_ms) {
201 Kevin 64
    // Delays the CPU for the given amount of time.
65
    // Note: Watch out for integer overflow! (max delay_ms = 107374) ??
199 Kevin 66
    unsigned int delay = delay_ms * MS_TO_CT_TICKS;
67
    unsigned int startTime = ReadCoreTimer();
68
    while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
69
}
70
 
71
void Delay_US(unsigned int delay_us) {
201 Kevin 72
    // Delays the CPU for the given amount of time.
73
    // Note: Watch out for integer overflow!
199 Kevin 74
    unsigned int delay = delay_us * US_TO_CT_TICKS;
75
    unsigned int startTime = ReadCoreTimer();
76
    while ((unsigned int)(ReadCoreTimer() - startTime) < delay) {};
77
}
78
 
193 Kevin 79
int main() {
80
    /* Configure the target for maximum performance at 80 MHz. */
199 Kevin 81
    // Note: This overrides the peripheral clock to 80Mhz regardless of config
82
    SYSTEMConfigPerformance(CPU_CLOCK_HZ);
193 Kevin 83
 
199 Kevin 84
    // Configure the interrupts for multiple vectors
193 Kevin 85
    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
86
 
199 Kevin 87
    // Set all analog I/O pins to digital
88
    AD1PCFGSET = 0xFFFF;
193 Kevin 89
 
212 Kevin 90
    // Initialize the SPI1 module
199 Kevin 91
    SPI1_DATA spi_data;
212 Kevin 92
    SPI1_Init(&spi_data, NULL);
199 Kevin 93
 
212 Kevin 94
    // Initialize the UART1 module
95
    UART1_DATA uart_data;
96
    UART1_Init(&uart_data, &Cube_Data_In);
97
 
98
    // Initializs the PWM2 output to 20MHz
199 Kevin 99
    PWM2_Init();
100
    PWM2_Start();
101
 
212 Kevin 102
    // Initialize the cube variables
199 Kevin 103
    CUBE_DATA cube_data;
206 Kevin 104
    Cube_Init(&cube_data, 0x40);
199 Kevin 105
 
207 Kevin 106
    // Start the cube update layer interrupt
199 Kevin 107
    // 2083 = 60Hz, 500 = 250Hz, 250 = 500Hz
206 Kevin 108
    TIMER5_DATA timer_5_data;
109
    TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
199 Kevin 110
    TIMER5_Start();
111
 
207 Kevin 112
    // Start the overlay rotation interrupt
206 Kevin 113
    TIMER4_DATA timer_4_data;
207 Kevin 114
    TIMER4_Init(&timer_4_data, &Cube_Text_Interrupt, 120000);
206 Kevin 115
 
207 Kevin 116
    // Process button inputs
201 Kevin 117
    BTN_DATA btn_data;
208 Kevin 118
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, &BTN3_Interrupt);
205 Kevin 119
 
201 Kevin 120
    // Begin display
200 Kevin 121
 
208 Kevin 122
//    Cube_Set_All(RED);
123
//    Delay_MS(6000);
124
//    Cube_Set_All(GREEN);
125
//    Delay_MS(6000);
126
//    Cube_Set_All(BLUE);
127
//    Delay_MS(6000);
207 Kevin 128
 
212 Kevin 129
    char start_text[] = "uC Started";
130
    UART1_Write(start_text, 10);
131
 
206 Kevin 132
    // Set the overlay text
208 Kevin 133
    char text_string[] = "Welcome to the CCM Lab    ";
134
    Cube_Text_Init(text_string, 26, 0xFF, 0xFF, 0xFF);
207 Kevin 135
    TIMER4_Start();
206 Kevin 136
 
199 Kevin 137
    // Loop through some preset animations
138
    while(1) {
207 Kevin 139
//        Animation_Solid_Colors(2,300);
140
//        Animation_Layer_Alternate(2,300);
141
//        Animation_Pixel_Alternate(1,200);
142
//        Animation_Full_Color_Sweep(2,1000);
199 Kevin 143
        Animation_Row_Column_Sweep(2,40);
144
        Animation_Cube_In_Cube(4,300);
205 Kevin 145
        Animation_Double_Rotation(2,40);
207 Kevin 146
        Animation_Pseudo_Random_Colors(10,300);
147
//        Animation_Random_Colors(10,300);
199 Kevin 148
    }
193 Kevin 149
}
150
 
200 Kevin 151
// Function call on button 1 press to change refresh rate
152
void BTN1_Interrupt(void) {
153
    static char state;
206 Kevin 154
    state = (state == 4) ? 0 : state + 1;
200 Kevin 155
    TIMER5_Stop();
156
    switch (state) {
157
        case 0:
207 Kevin 158
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
200 Kevin 159
            break;
160
        case 1:
207 Kevin 161
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2083); // 60Hz
200 Kevin 162
            break;
163
        case 2:
207 Kevin 164
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 4166); // 30Hz
200 Kevin 165
            break;
166
        case 3:
207 Kevin 167
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 12498); // 10Hz
200 Kevin 168
            break;
206 Kevin 169
        case 4:
207 Kevin 170
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 24996); // 5Hz
206 Kevin 171
            break;
200 Kevin 172
    }
173
    TIMER5_Start();
174
}
175
 
176
// Function call on button 2 press to change brightness
177
void BTN2_Interrupt(void) {
178
    static char state;
205 Kevin 179
    state = (state == 6) ? 0 : state + 1;
200 Kevin 180
    TIMER5_Stop();
181
    Delay_MS(1); // Need to wait for all SPI writes to complete
182
    char BC;
183
    switch (state) {
184
        case 0:
185
            BC = 0x01;
186
            break;
187
        case 1:
188
            BC = 0x08;
189
            break;
190
        case 2:
191
            BC = 0x10;
192
            break;
193
        case 3:
194
            BC = 0x20;
195
            break;
196
        case 4:
197
            BC = 0x40;
198
            break;
199
        case 5:
205 Kevin 200
            BC = 0x80;
200 Kevin 201
            break;
205 Kevin 202
        case 6:
203
            BC = 0xFF;
204
            break;
200 Kevin 205
    }
206
    Cube_Write_DCS(BC);
207
    TIMER5_Start();
208
}
209
 
206 Kevin 210
// Function call on button 3 press to change text scroll speed
211
void BTN3_Interrupt(void)  {
212
    static char state;
213
    state = (state == 4) ? 0 : state + 1;
214
    TIMER4_Stop();
215
    switch (state) {
216
        case 0:
217
            TIMER4_Init(NULL, &Cube_Text_Interrupt, 209712);
218
            break;
219
        case 1:
220
            TIMER4_Init(NULL, &Cube_Text_Interrupt, 180000);
221
            break;
222
        case 2:
223
            TIMER4_Init(NULL, &Cube_Text_Interrupt, 150000);
224
            break;
225
        case 3:
207 Kevin 226
            TIMER4_Init(NULL, &Cube_Text_Interrupt, 120000);
206 Kevin 227
            break;
228
        case 4:
207 Kevin 229
            TIMER4_Init(NULL, &Cube_Text_Interrupt, 90000);
206 Kevin 230
            break;
231
    }
232
    TIMER4_Start();
233
}
234
 
199 Kevin 235
void Animation_Solid_Colors(int iterations, int delay_ms) {
236
    int i;
237
    for (i = 0; i < iterations; i++) {
238
        Cube_Set_All(RED);
239
        Delay_MS(delay_ms);
240
        Cube_Set_All(GREEN);
241
        Delay_MS(delay_ms);
242
        Cube_Set_All(BLUE);
243
        Delay_MS(delay_ms);
244
    }
245
}
246
 
247
void Animation_Layer_Alternate(int iterations, int delay_ms) {
248
    int i,z;
249
    for (z = 0; z < iterations; z++) {
250
        for (i = 0; i < CUBE_LAYER_COUNT; i++) {
251
            if (i % 3 == 0)
252
                Cube_Set_Layer(i,RED);
253
            else if (i % 3 == 1)
254
                Cube_Set_Layer(i,GREEN);
255
            else
256
                Cube_Set_Layer(i,BLUE);
257
        }
258
        Delay_MS(delay_ms);
259
        for (i = 0; i < CUBE_LAYER_COUNT; i++) {
260
            if (i % 3 == 0)
261
                Cube_Set_Layer(i,GREEN);
262
            else if (i % 3 == 1)
263
                Cube_Set_Layer(i,BLUE);
264
            else
265
                Cube_Set_Layer(i,RED);
266
        }
267
        Delay_MS(delay_ms);
268
        for (i = 0; i < CUBE_LAYER_COUNT; i++) {
269
            if (i % 3 == 0)
270
                Cube_Set_Layer(i,BLUE);
271
            else if (i % 3 == 1)
272
                Cube_Set_Layer(i,RED);
273
            else
274
                Cube_Set_Layer(i,GREEN);
275
        }
276
        Delay_MS(delay_ms);
277
    }
278
}
279
 
280
void Animation_Pixel_Alternate(int iterations, int delay_ms) {
281
    int i,j,k,z;
282
    for (z = 0; z < iterations; z++) {
283
        for (i = 0; i < CUBE_LAYER_COUNT; i++) {
284
            Cube_Clear();
285
            for (j = 0; j < CUBE_ROW_COUNT; j++) {
286
                for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
287
                    int var = (j * 8) + k;
288
                    if (var % 3 == 0)
289
                        Cube_Set_Pixel(i,j,k,RED);
290
                    else if (var % 3 == 1)
291
                        Cube_Set_Pixel(i,j,k,GREEN);
292
                    else
293
                        Cube_Set_Pixel(i,j,k,BLUE);
294
                }
295
            }
296
            Delay_MS(delay_ms);
297
            Cube_Clear();
298
            for (j = 0; j < CUBE_ROW_COUNT; j++) {
299
                for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
300
                    int var = (j * 8) + k;
301
                    if (var % 3 == 0)
302
                        Cube_Set_Pixel(i,j,k,GREEN);
303
                    else if (var % 3 == 1)
304
                        Cube_Set_Pixel(i,j,k,BLUE);
305
                    else
306
                        Cube_Set_Pixel(i,j,k,RED);
307
                }
308
            }
309
            Delay_MS(delay_ms);
310
            Cube_Clear();
311
            for (j = 0; j < CUBE_ROW_COUNT; j++) {
312
                for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
313
                    int var = (j * 8) + k;
314
                    if (var % 3 == 0)
315
                        Cube_Set_Pixel(i,j,k,BLUE);
316
                    else if (var % 3 == 1)
317
                        Cube_Set_Pixel(i,j,k,RED);
318
                    else
319
                        Cube_Set_Pixel(i,j,k,GREEN);
320
                }
321
            }
322
            Delay_MS(delay_ms);
323
        }
324
    }
325
}
326
 
327
void Animation_Full_Color_Sweep(int iterations, int delay_us) {
328
    int i,z;
329
    for (z = 0; z < iterations; z++) {
330
        for (i = 0; i < 0x0FF; i+=2) {
331
            Cube_Set_All(i,0,0);
332
            Delay_US(delay_us);
333
        }
334
        for (i = 0; i < 0x0FF; i+=2) {
335
            Cube_Set_All(0x0FF,i,0);
336
            Delay_US(delay_us);
337
        }
338
        for (i = 0x0FF; i >= 0; i-=2) {
339
            Cube_Set_All(i,0x0FF,0);
340
            Delay_US(delay_us);
341
        }
342
        for (i = 0; i < 0x0FF; i+=2) {
343
            Cube_Set_All(0,0x0FF,i);
344
            Delay_US(delay_us);
345
        }
346
        for (i = 0; i < 0x0FF; i+=2) {
347
            Cube_Set_All(i,0x0FF,0x0FF);
348
            Delay_US(delay_us);
349
        }
350
        for (i = 0x0FF; i >= 0; i-=2) {
351
            Cube_Set_All(0x0FF,i,0x0FF);
352
            Delay_US(delay_us);
353
        }
354
        for (i = 0x0FF; i >= 0; i-=2) {
355
            Cube_Set_All(i,0,0x0FF);
356
            Delay_US(delay_us);
357
        }
358
        for (i = 0x100; i >= 0; i-=2) {
359
            Cube_Set_All(0,0,i);
360
            Delay_US(delay_us);
361
        }
362
    }
363
}
364
 
365
void Animation_Row_Column_Sweep(int iterations, int delay_ms) {
366
    int i,j,k,a,z;
367
    for (z = 0; z < iterations; z++) {
368
        for (i = 0; i < 3; i++) {
369
            for (j = 0; j < CUBE_ROW_COUNT; j++) {
370
                Cube_Clear();
371
                for (k = 0; k < CUBE_COLUMN_COUNT; k++)
372
                    if (i % 3 == 0)
373
                        for (a = 0; a < CUBE_LAYER_COUNT; a++)
374
                            Cube_Set_Pixel(a,j,k,RED);
375
                    else if (i % 3 == 1)
376
                        for (a = 0; a < CUBE_LAYER_COUNT; a++)
377
                            Cube_Set_Pixel(a,j,k,GREEN);
378
                    else
379
                        for (a = 0; a < CUBE_LAYER_COUNT; a++)
380
                            Cube_Set_Pixel(a,j,k,BLUE);
381
                Delay_MS(delay_ms);
382
            }
383
            for (j = 0; j < CUBE_ROW_COUNT; j++) {
384
                Cube_Clear();
385
                for (k = 0; k < CUBE_COLUMN_COUNT; k++)
386
                    if (i % 3 == 0)
387
                        for (a = 0; a < CUBE_LAYER_COUNT; a++)
388
                            Cube_Set_Pixel(a,k,j,RED);
389
                    else if (i % 3 == 1)
390
                        for (a = 0; a < CUBE_LAYER_COUNT; a++)
391
                            Cube_Set_Pixel(a,k,j,GREEN);
392
                    else
393
                        for (a = 0; a < CUBE_LAYER_COUNT; a++)
394
                            Cube_Set_Pixel(a,k,j,BLUE);
395
                Delay_MS(delay_ms);
396
            }
397
            for (j = CUBE_LAYER_COUNT-1; j >= 0; j--) {
398
                Cube_Clear();
399
                if (i % 3 == 0) {
400
                    for (k = 0; k < CUBE_LAYER_COUNT; k++)
401
                        if (k == j)
402
                            Cube_Set_Layer(k,RED);
403
                } else if (i % 3 == 1) {
404
                    for (k = 0; k < CUBE_LAYER_COUNT; k++)
405
                        if (k == j)
406
                            Cube_Set_Layer(k,GREEN);
407
                } else {
408
                    for (k = 0; k < CUBE_LAYER_COUNT; k++)
409
                        if (k == j)
410
                            Cube_Set_Layer(k,BLUE);
411
                }
412
                Delay_MS(delay_ms);
413
            }
414
        }
415
    }
416
}
417
 
418
void Animation_Pixel_Sweep(int iterations, int delay_ms) {
419
    int i,j,k,z,a;
420
    for (z = 0; z < iterations; z++) {
421
        for (a = 0; a < 3; a++) {
422
            for (i = 0; i < CUBE_LAYER_COUNT; i++) {
423
                for (j = 0; j < CUBE_ROW_COUNT; j++) {
424
                    for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
425
                        Cube_Clear();
426
                        if (a % 3 == 0) {
427
                            Cube_Set_Pixel(i,j,k,RED);
428
                        } else if (a % 3 == 1) {
429
                            Cube_Set_Pixel(i,j,k,GREEN);
430
                        } else {
431
                            Cube_Set_Pixel(i,j,k,BLUE);
432
                        }
433
                        Delay_MS(delay_ms);
434
                    }
435
                }
436
            }
437
        }
438
    }
439
}
440
 
441
void Animation_Pseudo_Random_Colors(int iterations, int delay_ms) {
442
    int i,j,k,z;
443
    for (z = 0; z < iterations; z++) {
444
        for (i = 0; i < CUBE_LAYER_COUNT; i++) {
445
            for (j = 0; j < CUBE_ROW_COUNT; j++) {
446
                for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
447
                    unsigned int a = rand();
448
                    if (a % 5 == 0)
449
                        Cube_Set_Pixel(i,j,k,RED);
450
                    else if (a % 5 == 1)
451
                        Cube_Set_Pixel(i,j,k,GREEN);
452
                    else if (a % 5 == 2)
453
                        Cube_Set_Pixel(i,j,k,BLUE);
454
                    else if (a % 5 == 3)
455
                        Cube_Set_Pixel(i,j,k,PURPLE);
456
                    else if (a % 5 == 4)
457
                        Cube_Set_Pixel(i,j,k,YELLOW);
458
                    else
459
                        Cube_Set_Pixel(i,j,k,ORANGE);
460
                }
461
            }
462
        }
463
        Delay_MS(delay_ms);
464
    }
465
}
466
 
467
void Animation_Random_Colors(int iterations, int delay_ms) {
468
    int i,j,k,z;
469
    for (z = 0; z < iterations; z++) {
470
        for (i = 0; i < CUBE_LAYER_COUNT; i++) {
471
            for (j = 0; j < CUBE_ROW_COUNT; j++) {
472
                for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
473
                    Cube_Set_Pixel(i,j,k,rand()&0x0FF,rand()&0x0FF,rand()&0x0FF);
474
                }
475
            }
476
        }
477
        Delay_MS(delay_ms);
478
    }
479
}
480
 
481
void Animation_Cube_In_Cube(int iterations, int delay_ms) {
482
    int z,x,i,j,k;
483
    for (z = 0; z < iterations; z++) {
484
        for (x = 0; x < 5; x++) {
485
            Cube_Clear();
486
            for (i = 0; i < CUBE_LAYER_COUNT; i++) {
487
                if ((x == 0 || x == 4)&&(i == 0 || i == 7)) {
488
                    Cube_Set_Layer(i,RED);
489
                } else if ((x == 1 || x == 4)&&(i == 1 || i == 6)) {
490
                    for (j = 1; j < CUBE_ROW_COUNT-1; j++)
491
                        for (k = 1; k < CUBE_COLUMN_COUNT-1; k++)
492
                            Cube_Set_Pixel(i,j,k,YELLOW);
493
                } else if ((x == 2 || x == 4)&&(i == 2 || i == 5)) {
494
                    for (j = 2; j < CUBE_ROW_COUNT-2; j++)
495
                        for (k = 2; k < CUBE_COLUMN_COUNT-2; k++)
496
                            Cube_Set_Pixel(i,j,k,GREEN);
497
                } else if ((x == 3 || x == 4)&&(i == 3 || i == 4)) {
498
                    for (j = 3; j < CUBE_ROW_COUNT-3; j++)
499
                        for (k = 3; k < CUBE_COLUMN_COUNT-3; k++)
500
                            Cube_Set_Pixel(i,j,k,BLUE);
501
                }
502
 
503
                if ((x == 0 || x == 4)&&(i > 0 && i < 8)) {
504
                    for (j = 0; j < 8; j++) {
505
                        Cube_Set_Pixel(i,j,0,RED);
506
                        Cube_Set_Pixel(i,j,7,RED);
507
                        Cube_Set_Pixel(i,0,j,RED);
508
                        Cube_Set_Pixel(i,7,j,RED);
509
                    }
510
                }
511
                if ((x == 1 || x == 4)&&(i > 1 && i < 7)) {
512
                    for (j = 1; j < 7; j++) {
513
                        Cube_Set_Pixel(i,j,1,YELLOW);
514
                        Cube_Set_Pixel(i,j,6,YELLOW);
515
                        Cube_Set_Pixel(i,1,j,YELLOW);
516
                        Cube_Set_Pixel(i,6,j,YELLOW);
517
                    }
518
                }
519
                if ((x == 2 || x == 4)&&(i > 2 && i < 6)) {
520
                    for (j = 2; j < 6; j++) {
521
                        Cube_Set_Pixel(i,j,2,GREEN);
522
                        Cube_Set_Pixel(i,j,5,GREEN);
523
                        Cube_Set_Pixel(i,2,j,GREEN);
524
                        Cube_Set_Pixel(i,5,j,GREEN);
525
                    }
526
                }
527
            }
528
            Delay_MS(delay_ms);
529
        }
530
    }
205 Kevin 531
}
532
 
533
void Animation_Double_Rotation(int iterations, int delay_ms) {
534
    Cube_Clear();
535
    int i,x,y,z;
536
    for (z = 0; z < 3; z++) {
537
        switch (z % 3) {
538
            case 0:
539
                for (y = 0; y < CUBE_LAYER_COUNT; y++) {
207 Kevin 540
                    Cube_Set_Pixel(y,0,0,RED);
541
                    Cube_Set_Pixel(y,1,1,RED);
542
                    Cube_Set_Pixel(y,2,2,RED);
543
                    Cube_Set_Pixel(y,3,3,RED);
544
                    Cube_Set_Pixel(y,4,4,RED);
545
                    Cube_Set_Pixel(y,5,5,RED);
546
                    Cube_Set_Pixel(y,6,6,RED);
547
                    Cube_Set_Pixel(y,7,7,RED);
205 Kevin 548
                }
549
                break;
550
            case 1:
551
                for (y = 0; y < CUBE_LAYER_COUNT; y++) {
207 Kevin 552
                    Cube_Set_Pixel(y,0,0,GREEN);
553
                    Cube_Set_Pixel(y,1,1,GREEN);
554
                    Cube_Set_Pixel(y,2,2,GREEN);
555
                    Cube_Set_Pixel(y,3,3,GREEN);
556
                    Cube_Set_Pixel(y,4,4,GREEN);
557
                    Cube_Set_Pixel(y,5,5,GREEN);
558
                    Cube_Set_Pixel(y,6,6,GREEN);
559
                    Cube_Set_Pixel(y,7,7,GREEN);
205 Kevin 560
                }
561
                break;
562
            case 2:
563
                for (y = 0; y < CUBE_LAYER_COUNT; y++) {
207 Kevin 564
                    Cube_Set_Pixel(y,0,0,BLUE);
565
                    Cube_Set_Pixel(y,1,1,BLUE);
566
                    Cube_Set_Pixel(y,2,2,BLUE);
567
                    Cube_Set_Pixel(y,3,3,BLUE);
568
                    Cube_Set_Pixel(y,4,4,BLUE);
569
                    Cube_Set_Pixel(y,5,5,BLUE);
570
                    Cube_Set_Pixel(y,6,6,BLUE);
571
                    Cube_Set_Pixel(y,7,7,BLUE);
205 Kevin 572
                }
573
                break;
574
        }
575
 
576
        for (i = 0; i < iterations; i++) {
577
            for (x = 0; x < 28; x++) {
578
                Delay_MS(delay_ms);
206 Kevin 579
                Cube_Rotate(0);
205 Kevin 580
            }
581
        }
582
    }
199 Kevin 583
}