Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 263 → Rev 264

/PIC Stuff/Cerebot_32MX7_LED_Cube/ANIMATIONS.c
232,50 → 232,22
}
 
void Animation_Cube_In_Cube(uint16_t delay_ms) {
uint8_t x,i,j,k;
uint8_t x;
for (x = 0; x < 5; x++) {
Cube_Clear();
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if ((x == 0 || x == 4)&&(i == 0 || i == 7)) {
Cube_Set_Layer(i,RED);
} else if ((x == 1 || x == 4)&&(i == 1 || i == 6)) {
for (j = 1; j < CUBE_ROW_COUNT-1; j++)
for (k = 1; k < CUBE_COLUMN_COUNT-1; k++)
Cube_Set_Pixel(i,j,k,YELLOW);
} else if ((x == 2 || x == 4)&&(i == 2 || i == 5)) {
for (j = 2; j < CUBE_ROW_COUNT-2; j++)
for (k = 2; k < CUBE_COLUMN_COUNT-2; k++)
Cube_Set_Pixel(i,j,k,GREEN);
} else if ((x == 3 || x == 4)&&(i == 3 || i == 4)) {
for (j = 3; j < CUBE_ROW_COUNT-3; j++)
for (k = 3; k < CUBE_COLUMN_COUNT-3; k++)
Cube_Set_Pixel(i,j,k,BLUE);
}
 
if ((x == 0 || x == 4)&&(i > 0 && i < 8)) {
for (j = 0; j < 8; j++) {
Cube_Set_Pixel(i,j,0,RED);
Cube_Set_Pixel(i,j,7,RED);
Cube_Set_Pixel(i,0,j,RED);
Cube_Set_Pixel(i,7,j,RED);
}
}
if ((x == 1 || x == 4)&&(i > 1 && i < 7)) {
for (j = 1; j < 7; j++) {
Cube_Set_Pixel(i,j,1,YELLOW);
Cube_Set_Pixel(i,j,6,YELLOW);
Cube_Set_Pixel(i,1,j,YELLOW);
Cube_Set_Pixel(i,6,j,YELLOW);
}
}
if ((x == 2 || x == 4)&&(i > 2 && i < 6)) {
for (j = 2; j < 6; j++) {
Cube_Set_Pixel(i,j,2,GREEN);
Cube_Set_Pixel(i,j,5,GREEN);
Cube_Set_Pixel(i,2,j,GREEN);
Cube_Set_Pixel(i,5,j,GREEN);
}
}
if (x == 0)
Cube_Set_Shell(0, RED);
else if (x == 1)
Cube_Set_Shell(1, YELLOW);
else if (x == 2)
Cube_Set_Shell(2, GREEN);
else if (x == 3)
Cube_Set_Shell(3, BLUE);
else {
Cube_Set_Shell(0, RED);
Cube_Set_Shell(1, YELLOW);
Cube_Set_Shell(2, GREEN);
Cube_Set_Shell(3, BLUE);
}
Delay_MS(delay_ms);
}
380,3 → 352,121
}
}
}
 
void Animation_Wave1(uint16_t delay_ms) {
uint8_t i, j;
uint8_t data[8];
for (i = 0; i < 16; i++) {
for (j = 0; j < 8; j++)
data[j] = rand() % 9;
Cube_Shift_Waterfall(data);
Delay_MS(delay_ms);
}
}
 
void Animation_Wave2(uint16_t delay_ms) {
uint8_t i, j;
uint8_t data[8];
for (i = 0; i < 16; i++) {
for (j = 0; j < 8; j++)
data[j] = rand() % 9;
Cube_Shift_Waterfall2(data);
Delay_MS(delay_ms);
}
}
 
void Animation_Sphere(uint16_t delay_ms) {
Cube_Clear();
Cube_Set_Sphere(0, RED);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(1, ORANGE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(2, YELLOW);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(3, GREEN);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(4, BLUE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(5, PURPLE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(6, RED);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(7, ORANGE);
Delay_MS(delay_ms);
Cube_Clear();
Cube_Set_Sphere(8, YELLOW);
Delay_MS(delay_ms);
 
}
 
void Animation_Sawtooth(uint16_t delay_ms) {
uint8_t i;
uint8_t dir = 1;
uint8_t layer_dir = 1;
uint8_t layer_min = 0;
uint8_t layer_max = CUBE_LAYER_COUNT;
uint8_t layer = layer_min;
 
for (i = 0; i < 48; i++) {
Cube_Set_Row(7, 0x00, 0x00, 0x00);
Cube_Set_Pixel(layer, 7, 0, RED);
Cube_Set_Pixel(layer, 7, 1, ORANGE);
Cube_Set_Pixel(layer, 7, 2, YELLOW);
Cube_Set_Pixel(layer, 7, 3, GREEN);
Cube_Set_Pixel(layer, 7, 4, TEAL);
Cube_Set_Pixel(layer, 7, 5, BLUE);
Cube_Set_Pixel(layer, 7, 6, PURPLE);
Cube_Set_Pixel(layer, 7, 7, WHITE);
if (dir)
layer++;
else
layer--;
 
// Decrease the maximum layer
if (layer == layer_min) {
dir = 1;
if (layer_dir)
layer_max--;
else
layer_max++;
}
 
// Increase the minimum layer
if (layer == layer_max - 1) {
dir = 0;
if (layer_dir)
layer_min++;
else
layer_min--;
}
 
// Change the layer gap to expansion
if (layer_max - layer_min < 3) {
if (layer_dir)
layer_dir = 0;
else
layer_dir = 1;
}
 
// Change the layer gap to reduction
if (layer == 0) {
if (layer_dir)
layer_dir = 0;
else
layer_dir = 1;
}
Delay_MS(delay_ms);
Cube_Shift_Row(0);
}
}
/PIC Stuff/Cerebot_32MX7_LED_Cube/ANIMATIONS.h
11,6 → 11,10
void Animation_Random_Colors(uint16_t delay_ms);
void Animation_Cube_In_Cube(uint16_t delay_ms);
void Animation_Double_Rotation(uint16_t delay_ms);
void Animation_Wave1(uint16_t delay_ms);
void Animation_Wave2(uint16_t delay_ms);
void Animation_Sphere(uint16_t delay_ms);
void Animation_Sawtooth(uint16_t delay_ms);
 
void Animation_Cube_In_Out(uint16_t delay_ms, uint16_t r, uint16_t g, uint16_t b);
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/CUBE.c
4,6 → 4,7
#include "glcdfont.h"
#include "UART1.h"
#include "ETHERNET.h"
#include "TIMER4.h"
 
static CUBE_DATA *cube_data_ptr;
 
195,6 → 196,64
}
}
 
void Cube_Set_Row(uint8_t row, uint16_t R, uint16_t G, uint16_t B) {
// Set the specified row to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint8_t column, layer;
for (layer = 0; layer < CUBE_LAYER_COUNT; layer++) {
for (column = 0; column < CUBE_COLUMN_COUNT; column++) {
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
case 0:
cube_data_ptr->GCS[layer][var+0] = R & 0xFF;
cube_data_ptr->GCS[layer][var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][var+2] = G >> 4;
cube_data_ptr->GCS[layer][var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0xF0) | (B >> 8);
break;
case 1:
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0x0F) | (R << 4);
cube_data_ptr->GCS[layer][var+5] = R >> 4;
cube_data_ptr->GCS[layer][var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][var+8] = B >> 4;
break;
}
}
}
}
 
void Cube_Set_Column(uint8_t column, uint16_t R, uint16_t G, uint16_t B) {
// Set the specified row to the given color
R &= 0x0FFF;
G &= 0x0FFF;
B &= 0x0FFF;
uint8_t row, layer;
for (layer = 0; layer < CUBE_LAYER_COUNT; layer++) {
for (row = 0; row < CUBE_COLUMN_COUNT; row++) {
uint16_t var = row * GCS_REG_SIZE + (column / 2 * 9);
switch (column % 2) {
case 0:
cube_data_ptr->GCS[layer][var+0] = R & 0xFF;
cube_data_ptr->GCS[layer][var+1] = (G << 4) | (R >> 8);
cube_data_ptr->GCS[layer][var+2] = G >> 4;
cube_data_ptr->GCS[layer][var+3] = B & 0xFF;
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0xF0) | (B >> 8);
break;
case 1:
cube_data_ptr->GCS[layer][var+4] = (cube_data_ptr->GCS[layer][var+4] & 0x0F) | (R << 4);
cube_data_ptr->GCS[layer][var+5] = R >> 4;
cube_data_ptr->GCS[layer][var+6] = G & 0xFF;
cube_data_ptr->GCS[layer][var+7] = (B << 4) | (G >> 8);
cube_data_ptr->GCS[layer][var+8] = B >> 4;
break;
}
}
}
}
 
void Cube_Set_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t R, uint16_t G, uint16_t B) {
// Set the specified pixel to the given color
R &= 0x0FFF;
244,6 → 303,639
Cube_Set_Pixel(layer2, row2, column2, prev_R, prev_G, prev_B);
}
 
void Cube_Set_Sphere(uint8_t layer, uint8_t R, uint8_t G, uint8_t B) {
// Super code inefficient (or is it?) lookup table
switch (layer) {
case 0:
Cube_Set_Pixel(3, 3, 3, R, G, B);
Cube_Set_Pixel(3, 3, 4, R, G, B);
Cube_Set_Pixel(3, 4, 3, R, G, B);
Cube_Set_Pixel(3, 4, 4, R, G, B);
Cube_Set_Pixel(4, 3, 3, R, G, B);
Cube_Set_Pixel(4, 3, 4, R, G, B);
Cube_Set_Pixel(4, 4, 3, R, G, B);
Cube_Set_Pixel(4, 4, 4, R, G, B);
break;
case 1:
Cube_Set_Pixel(2, 3, 3, R, G, B);
Cube_Set_Pixel(2, 3, 4, R, G, B);
Cube_Set_Pixel(2, 4, 3, R, G, B);
Cube_Set_Pixel(2, 4, 4, R, G, B);
 
Cube_Set_Pixel(5, 3, 3, R, G, B);
Cube_Set_Pixel(5, 3, 4, R, G, B);
Cube_Set_Pixel(5, 4, 3, R, G, B);
Cube_Set_Pixel(5, 4, 4, R, G, B);
 
Cube_Set_Pixel(3, 2, 3, R, G, B);
Cube_Set_Pixel(3, 2, 4, R, G, B);
Cube_Set_Pixel(3, 5, 3, R, G, B);
Cube_Set_Pixel(3, 5, 4, R, G, B);
Cube_Set_Pixel(3, 3, 2, R, G, B);
Cube_Set_Pixel(3, 4, 2, R, G, B);
Cube_Set_Pixel(3, 3, 5, R, G, B);
Cube_Set_Pixel(3, 4, 5, R, G, B);
 
Cube_Set_Pixel(4, 2, 3, R, G, B);
Cube_Set_Pixel(4, 2, 4, R, G, B);
Cube_Set_Pixel(4, 5, 3, R, G, B);
Cube_Set_Pixel(4, 5, 4, R, G, B);
Cube_Set_Pixel(4, 3, 2, R, G, B);
Cube_Set_Pixel(4, 4, 2, R, G, B);
Cube_Set_Pixel(4, 3, 5, R, G, B);
Cube_Set_Pixel(4, 4, 5, R, G, B);
break;
case 2:
Cube_Set_Pixel(1, 3, 3, R, G, B);
Cube_Set_Pixel(1, 3, 4, R, G, B);
Cube_Set_Pixel(1, 4, 3, R, G, B);
Cube_Set_Pixel(1, 4, 4, R, G, B);
Cube_Set_Pixel(6, 3, 3, R, G, B);
Cube_Set_Pixel(6, 3, 4, R, G, B);
Cube_Set_Pixel(6, 4, 3, R, G, B);
Cube_Set_Pixel(6, 4, 4, R, G, B);
 
Cube_Set_Pixel(3, 1, 3, R, G, B);
Cube_Set_Pixel(3, 1, 4, R, G, B);
Cube_Set_Pixel(3, 6, 3, R, G, B);
Cube_Set_Pixel(3, 6, 4, R, G, B);
Cube_Set_Pixel(3, 3, 1, R, G, B);
Cube_Set_Pixel(3, 4, 1, R, G, B);
Cube_Set_Pixel(3, 3, 6, R, G, B);
Cube_Set_Pixel(3, 4, 6, R, G, B);
 
Cube_Set_Pixel(3, 2, 2, R, G, B);
Cube_Set_Pixel(3, 2, 5, R, G, B);
Cube_Set_Pixel(3, 5, 5, R, G, B);
Cube_Set_Pixel(3, 5, 2, R, G, B);
 
Cube_Set_Pixel(4, 1, 3, R, G, B);
Cube_Set_Pixel(4, 1, 4, R, G, B);
Cube_Set_Pixel(4, 6, 3, R, G, B);
Cube_Set_Pixel(4, 6, 4, R, G, B);
Cube_Set_Pixel(4, 3, 1, R, G, B);
Cube_Set_Pixel(4, 4, 1, R, G, B);
Cube_Set_Pixel(4, 3, 6, R, G, B);
Cube_Set_Pixel(4, 4, 6, R, G, B);
 
Cube_Set_Pixel(4, 2, 2, R, G, B);
Cube_Set_Pixel(4, 2, 5, R, G, B);
Cube_Set_Pixel(4, 5, 5, R, G, B);
Cube_Set_Pixel(4, 5, 2, R, G, B);
 
Cube_Set_Pixel(2, 3, 2, R, G, B);
Cube_Set_Pixel(2, 4, 2, R, G, B);
Cube_Set_Pixel(2, 3, 5, R, G, B);
Cube_Set_Pixel(2, 4, 5, R, G, B);
Cube_Set_Pixel(2, 2, 3, R, G, B);
Cube_Set_Pixel(2, 2, 4, R, G, B);
Cube_Set_Pixel(2, 5, 3, R, G, B);
Cube_Set_Pixel(2, 5, 4, R, G, B);
 
Cube_Set_Pixel(2, 2, 2, R, G, B);
Cube_Set_Pixel(2, 2, 5, R, G, B);
Cube_Set_Pixel(2, 5, 2, R, G, B);
Cube_Set_Pixel(2, 5, 5, R, G, B);
 
Cube_Set_Pixel(5, 3, 2, R, G, B);
Cube_Set_Pixel(5, 4, 2, R, G, B);
Cube_Set_Pixel(5, 3, 5, R, G, B);
Cube_Set_Pixel(5, 4, 5, R, G, B);
Cube_Set_Pixel(5, 2, 3, R, G, B);
Cube_Set_Pixel(5, 2, 4, R, G, B);
Cube_Set_Pixel(5, 5, 3, R, G, B);
Cube_Set_Pixel(5, 5, 4, R, G, B);
 
Cube_Set_Pixel(5, 2, 2, R, G, B);
Cube_Set_Pixel(5, 2, 5, R, G, B);
Cube_Set_Pixel(5, 5, 2, R, G, B);
Cube_Set_Pixel(5, 5, 5, R, G, B);
break;
case 3:
Cube_Set_Pixel(0, 3, 3, R, G, B);
Cube_Set_Pixel(0, 3, 4, R, G, B);
Cube_Set_Pixel(0, 4, 3, R, G, B);
Cube_Set_Pixel(0, 4, 4, R, G, B);
Cube_Set_Pixel(7, 3, 3, R, G, B);
Cube_Set_Pixel(7, 3, 4, R, G, B);
Cube_Set_Pixel(7, 4, 3, R, G, B);
Cube_Set_Pixel(7, 4, 4, R, G, B);
 
Cube_Set_Pixel(3, 0, 3, R, G, B);
Cube_Set_Pixel(3, 0, 4, R, G, B);
Cube_Set_Pixel(3, 7, 3, R, G, B);
Cube_Set_Pixel(3, 7, 4, R, G, B);
Cube_Set_Pixel(3, 3, 0, R, G, B);
Cube_Set_Pixel(3, 4, 0, R, G, B);
Cube_Set_Pixel(3, 3, 7, R, G, B);
Cube_Set_Pixel(3, 4, 7, R, G, B);
 
Cube_Set_Pixel(3, 2, 6, R, G, B);
Cube_Set_Pixel(3, 1, 5, R, G, B);
Cube_Set_Pixel(3, 6, 2, R, G, B);
Cube_Set_Pixel(3, 5, 1, R, G, B);
Cube_Set_Pixel(3, 1, 2, R, G, B);
Cube_Set_Pixel(3, 2, 1, R, G, B);
Cube_Set_Pixel(3, 6, 5, R, G, B);
Cube_Set_Pixel(3, 5, 6, R, G, B);
 
Cube_Set_Pixel(4, 0, 3, R, G, B);
Cube_Set_Pixel(4, 0, 4, R, G, B);
Cube_Set_Pixel(4, 7, 3, R, G, B);
Cube_Set_Pixel(4, 7, 4, R, G, B);
Cube_Set_Pixel(4, 3, 0, R, G, B);
Cube_Set_Pixel(4, 4, 0, R, G, B);
Cube_Set_Pixel(4, 3, 7, R, G, B);
Cube_Set_Pixel(4, 4, 7, R, G, B);
 
Cube_Set_Pixel(4, 2, 6, R, G, B);
Cube_Set_Pixel(4, 1, 5, R, G, B);
Cube_Set_Pixel(4, 6, 2, R, G, B);
Cube_Set_Pixel(4, 5, 1, R, G, B);
Cube_Set_Pixel(4, 1, 2, R, G, B);
Cube_Set_Pixel(4, 2, 1, R, G, B);
Cube_Set_Pixel(4, 6, 5, R, G, B);
Cube_Set_Pixel(4, 5, 6, R, G, B);
 
Cube_Set_Pixel(1, 2, 5, R, G, B);
Cube_Set_Pixel(1, 2, 4, R, G, B);
Cube_Set_Pixel(1, 2, 3, R, G, B);
Cube_Set_Pixel(1, 2, 2, R, G, B);
Cube_Set_Pixel(1, 3, 5, R, G, B);
Cube_Set_Pixel(1, 3, 2, R, G, B);
Cube_Set_Pixel(1, 4, 5, R, G, B);
Cube_Set_Pixel(1, 4, 2, R, G, B);
Cube_Set_Pixel(1, 5, 5, R, G, B);
Cube_Set_Pixel(1, 5, 4, R, G, B);
Cube_Set_Pixel(1, 5, 3, R, G, B);
Cube_Set_Pixel(1, 5, 2, R, G, B);
 
Cube_Set_Pixel(2, 1, 5, R, G, B);
Cube_Set_Pixel(2, 1, 4, R, G, B);
Cube_Set_Pixel(2, 1, 3, R, G, B);
Cube_Set_Pixel(2, 1, 2, R, G, B);
Cube_Set_Pixel(2, 6, 5, R, G, B);
Cube_Set_Pixel(2, 6, 4, R, G, B);
Cube_Set_Pixel(2, 6, 3, R, G, B);
Cube_Set_Pixel(2, 6, 2, R, G, B);
Cube_Set_Pixel(2, 2, 6, R, G, B);
Cube_Set_Pixel(2, 3, 6, R, G, B);
Cube_Set_Pixel(2, 4, 6, R, G, B);
Cube_Set_Pixel(2, 5, 6, R, G, B);
Cube_Set_Pixel(2, 2, 1, R, G, B);
Cube_Set_Pixel(2, 3, 1, R, G, B);
Cube_Set_Pixel(2, 4, 1, R, G, B);
Cube_Set_Pixel(2, 5, 1, R, G, B);
 
Cube_Set_Pixel(5, 1, 5, R, G, B);
Cube_Set_Pixel(5, 1, 4, R, G, B);
Cube_Set_Pixel(5, 1, 3, R, G, B);
Cube_Set_Pixel(5, 1, 2, R, G, B);
Cube_Set_Pixel(5, 6, 5, R, G, B);
Cube_Set_Pixel(5, 6, 4, R, G, B);
Cube_Set_Pixel(5, 6, 3, R, G, B);
Cube_Set_Pixel(5, 6, 2, R, G, B);
Cube_Set_Pixel(5, 2, 6, R, G, B);
Cube_Set_Pixel(5, 3, 6, R, G, B);
Cube_Set_Pixel(5, 4, 6, R, G, B);
Cube_Set_Pixel(5, 5, 6, R, G, B);
Cube_Set_Pixel(5, 2, 1, R, G, B);
Cube_Set_Pixel(5, 3, 1, R, G, B);
Cube_Set_Pixel(5, 4, 1, R, G, B);
Cube_Set_Pixel(5, 5, 1, R, G, B);
 
Cube_Set_Pixel(6, 2, 5, R, G, B);
Cube_Set_Pixel(6, 2, 4, R, G, B);
Cube_Set_Pixel(6, 2, 3, R, G, B);
Cube_Set_Pixel(6, 2, 2, R, G, B);
Cube_Set_Pixel(6, 3, 5, R, G, B);
Cube_Set_Pixel(6, 3, 2, R, G, B);
Cube_Set_Pixel(6, 4, 5, R, G, B);
Cube_Set_Pixel(6, 4, 2, R, G, B);
Cube_Set_Pixel(6, 5, 5, R, G, B);
Cube_Set_Pixel(6, 5, 4, R, G, B);
Cube_Set_Pixel(6, 5, 3, R, G, B);
Cube_Set_Pixel(6, 5, 2, R, G, B);
break;
case 4:
Cube_Set_Pixel(0, 2, 5, R, G, B);
Cube_Set_Pixel(0, 2, 4, R, G, B);
Cube_Set_Pixel(0, 2, 3, R, G, B);
Cube_Set_Pixel(0, 2, 2, R, G, B);
Cube_Set_Pixel(0, 3, 5, R, G, B);
Cube_Set_Pixel(0, 3, 2, R, G, B);
Cube_Set_Pixel(0, 4, 5, R, G, B);
Cube_Set_Pixel(0, 4, 2, R, G, B);
Cube_Set_Pixel(0, 5, 5, R, G, B);
Cube_Set_Pixel(0, 5, 4, R, G, B);
Cube_Set_Pixel(0, 5, 3, R, G, B);
Cube_Set_Pixel(0, 5, 2, R, G, B);
 
Cube_Set_Pixel(7, 2, 5, R, G, B);
Cube_Set_Pixel(7, 2, 4, R, G, B);
Cube_Set_Pixel(7, 2, 3, R, G, B);
Cube_Set_Pixel(7, 2, 2, R, G, B);
Cube_Set_Pixel(7, 3, 5, R, G, B);
Cube_Set_Pixel(7, 3, 2, R, G, B);
Cube_Set_Pixel(7, 4, 5, R, G, B);
Cube_Set_Pixel(7, 4, 2, R, G, B);
Cube_Set_Pixel(7, 5, 5, R, G, B);
Cube_Set_Pixel(7, 5, 4, R, G, B);
Cube_Set_Pixel(7, 5, 3, R, G, B);
Cube_Set_Pixel(7, 5, 2, R, G, B);
 
Cube_Set_Pixel(1, 1, 5, R, G, B);
Cube_Set_Pixel(1, 1, 4, R, G, B);
Cube_Set_Pixel(1, 1, 3, R, G, B);
Cube_Set_Pixel(1, 1, 2, R, G, B);
Cube_Set_Pixel(1, 6, 5, R, G, B);
Cube_Set_Pixel(1, 6, 4, R, G, B);
Cube_Set_Pixel(1, 6, 3, R, G, B);
Cube_Set_Pixel(1, 6, 2, R, G, B);
Cube_Set_Pixel(1, 2, 6, R, G, B);
Cube_Set_Pixel(1, 3, 6, R, G, B);
Cube_Set_Pixel(1, 4, 6, R, G, B);
Cube_Set_Pixel(1, 5, 6, R, G, B);
Cube_Set_Pixel(1, 2, 1, R, G, B);
Cube_Set_Pixel(1, 3, 1, R, G, B);
Cube_Set_Pixel(1, 4, 1, R, G, B);
Cube_Set_Pixel(1, 5, 1, R, G, B);
 
Cube_Set_Pixel(6, 1, 5, R, G, B);
Cube_Set_Pixel(6, 1, 4, R, G, B);
Cube_Set_Pixel(6, 1, 3, R, G, B);
Cube_Set_Pixel(6, 1, 2, R, G, B);
Cube_Set_Pixel(6, 6, 5, R, G, B);
Cube_Set_Pixel(6, 6, 4, R, G, B);
Cube_Set_Pixel(6, 6, 3, R, G, B);
Cube_Set_Pixel(6, 6, 2, R, G, B);
Cube_Set_Pixel(6, 2, 6, R, G, B);
Cube_Set_Pixel(6, 3, 6, R, G, B);
Cube_Set_Pixel(6, 4, 6, R, G, B);
Cube_Set_Pixel(6, 5, 6, R, G, B);
Cube_Set_Pixel(6, 2, 1, R, G, B);
Cube_Set_Pixel(6, 3, 1, R, G, B);
Cube_Set_Pixel(6, 4, 1, R, G, B);
Cube_Set_Pixel(6, 5, 1, R, G, B);
 
Cube_Set_Pixel(2, 0, 5, R, G, B);
Cube_Set_Pixel(2, 0, 4, R, G, B);
Cube_Set_Pixel(2, 0, 3, R, G, B);
Cube_Set_Pixel(2, 0, 2, R, G, B);
Cube_Set_Pixel(2, 7, 5, R, G, B);
Cube_Set_Pixel(2, 7, 4, R, G, B);
Cube_Set_Pixel(2, 7, 3, R, G, B);
Cube_Set_Pixel(2, 7, 2, R, G, B);
Cube_Set_Pixel(2, 5, 0, R, G, B);
Cube_Set_Pixel(2, 4, 0, R, G, B);
Cube_Set_Pixel(2, 3, 0, R, G, B);
Cube_Set_Pixel(2, 2, 0, R, G, B);
Cube_Set_Pixel(2, 5, 7, R, G, B);
Cube_Set_Pixel(2, 4, 7, R, G, B);
Cube_Set_Pixel(2, 3, 7, R, G, B);
Cube_Set_Pixel(2, 2, 7, R, G, B);
Cube_Set_Pixel(2, 1, 1, R, G, B);
Cube_Set_Pixel(2, 1, 6, R, G, B);
Cube_Set_Pixel(2, 6, 1, R, G, B);
Cube_Set_Pixel(2, 6, 6, R, G, B);
 
Cube_Set_Pixel(5, 0, 5, R, G, B);
Cube_Set_Pixel(5, 0, 4, R, G, B);
Cube_Set_Pixel(5, 0, 3, R, G, B);
Cube_Set_Pixel(5, 0, 2, R, G, B);
Cube_Set_Pixel(5, 7, 5, R, G, B);
Cube_Set_Pixel(5, 7, 4, R, G, B);
Cube_Set_Pixel(5, 7, 3, R, G, B);
Cube_Set_Pixel(5, 7, 2, R, G, B);
Cube_Set_Pixel(5, 5, 0, R, G, B);
Cube_Set_Pixel(5, 4, 0, R, G, B);
Cube_Set_Pixel(5, 3, 0, R, G, B);
Cube_Set_Pixel(5, 2, 0, R, G, B);
Cube_Set_Pixel(5, 5, 7, R, G, B);
Cube_Set_Pixel(5, 4, 7, R, G, B);
Cube_Set_Pixel(5, 3, 7, R, G, B);
Cube_Set_Pixel(5, 2, 7, R, G, B);
Cube_Set_Pixel(5, 1, 1, R, G, B);
Cube_Set_Pixel(5, 1, 6, R, G, B);
Cube_Set_Pixel(5, 6, 1, R, G, B);
Cube_Set_Pixel(5, 6, 6, R, G, B);
 
Cube_Set_Pixel(3, 0, 2, R, G, B);
Cube_Set_Pixel(3, 0, 5, R, G, B);
Cube_Set_Pixel(3, 2, 0, R, G, B);
Cube_Set_Pixel(3, 5, 0, R, G, B);
Cube_Set_Pixel(3, 7, 2, R, G, B);
Cube_Set_Pixel(3, 7, 5, R, G, B);
Cube_Set_Pixel(3, 2, 7, R, G, B);
Cube_Set_Pixel(3, 5, 7, R, G, B);
Cube_Set_Pixel(3, 1, 1, R, G, B);
Cube_Set_Pixel(3, 1, 6, R, G, B);
Cube_Set_Pixel(3, 6, 1, R, G, B);
Cube_Set_Pixel(3, 6, 6, R, G, B);
 
Cube_Set_Pixel(4, 0, 2, R, G, B);
Cube_Set_Pixel(4, 0, 5, R, G, B);
Cube_Set_Pixel(4, 2, 0, R, G, B);
Cube_Set_Pixel(4, 5, 0, R, G, B);
Cube_Set_Pixel(4, 7, 2, R, G, B);
Cube_Set_Pixel(4, 7, 5, R, G, B);
Cube_Set_Pixel(4, 2, 7, R, G, B);
Cube_Set_Pixel(4, 5, 7, R, G, B);
Cube_Set_Pixel(4, 1, 1, R, G, B);
Cube_Set_Pixel(4, 1, 6, R, G, B);
Cube_Set_Pixel(4, 6, 1, R, G, B);
Cube_Set_Pixel(4, 6, 6, R, G, B);
break;
case 5:
Cube_Set_Pixel(0, 1, 5, R, G, B);
Cube_Set_Pixel(0, 1, 4, R, G, B);
Cube_Set_Pixel(0, 1, 3, R, G, B);
Cube_Set_Pixel(0, 1, 2, R, G, B);
Cube_Set_Pixel(0, 6, 5, R, G, B);
Cube_Set_Pixel(0, 6, 4, R, G, B);
Cube_Set_Pixel(0, 6, 3, R, G, B);
Cube_Set_Pixel(0, 6, 2, R, G, B);
Cube_Set_Pixel(0, 2, 6, R, G, B);
Cube_Set_Pixel(0, 3, 6, R, G, B);
Cube_Set_Pixel(0, 4, 6, R, G, B);
Cube_Set_Pixel(0, 5, 6, R, G, B);
Cube_Set_Pixel(0, 2, 1, R, G, B);
Cube_Set_Pixel(0, 3, 1, R, G, B);
Cube_Set_Pixel(0, 4, 1, R, G, B);
Cube_Set_Pixel(0, 5, 1, R, G, B);
 
Cube_Set_Pixel(1, 0, 2, R, G, B);
Cube_Set_Pixel(1, 0, 3, R, G, B);
Cube_Set_Pixel(1, 0, 4, R, G, B);
Cube_Set_Pixel(1, 0, 5, R, G, B);
Cube_Set_Pixel(1, 1, 6, R, G, B);
Cube_Set_Pixel(1, 2, 7, R, G, B);
Cube_Set_Pixel(1, 3, 7, R, G, B);
Cube_Set_Pixel(1, 4, 7, R, G, B);
Cube_Set_Pixel(1, 5, 7, R, G, B);
Cube_Set_Pixel(1, 6, 6, R, G, B);
Cube_Set_Pixel(1, 7, 5, R, G, B);
Cube_Set_Pixel(1, 7, 4, R, G, B);
Cube_Set_Pixel(1, 7, 3, R, G, B);
Cube_Set_Pixel(1, 7, 2, R, G, B);
Cube_Set_Pixel(1, 6, 1, R, G, B);
Cube_Set_Pixel(1, 5, 0, R, G, B);
Cube_Set_Pixel(1, 4, 0, R, G, B);
Cube_Set_Pixel(1, 3, 0, R, G, B);
Cube_Set_Pixel(1, 2, 0, R, G, B);
Cube_Set_Pixel(1, 1, 1, R, G, B);
 
Cube_Set_Pixel(2, 0, 1, R, G, B);
Cube_Set_Pixel(2, 1, 0, R, G, B);
Cube_Set_Pixel(2, 0, 6, R, G, B);
Cube_Set_Pixel(2, 1, 7, R, G, B);
Cube_Set_Pixel(2, 6, 7, R, G, B);
Cube_Set_Pixel(2, 7, 6, R, G, B);
Cube_Set_Pixel(2, 6, 0, R, G, B);
Cube_Set_Pixel(2, 7, 1, R, G, B);
 
Cube_Set_Pixel(3, 0, 1, R, G, B);
Cube_Set_Pixel(3, 1, 0, R, G, B);
Cube_Set_Pixel(3, 0, 6, R, G, B);
Cube_Set_Pixel(3, 1, 7, R, G, B);
Cube_Set_Pixel(3, 6, 7, R, G, B);
Cube_Set_Pixel(3, 7, 6, R, G, B);
Cube_Set_Pixel(3, 6, 0, R, G, B);
Cube_Set_Pixel(3, 7, 1, R, G, B);
 
Cube_Set_Pixel(4, 0, 1, R, G, B);
Cube_Set_Pixel(4, 1, 0, R, G, B);
Cube_Set_Pixel(4, 0, 6, R, G, B);
Cube_Set_Pixel(4, 1, 7, R, G, B);
Cube_Set_Pixel(4, 6, 7, R, G, B);
Cube_Set_Pixel(4, 7, 6, R, G, B);
Cube_Set_Pixel(4, 6, 0, R, G, B);
Cube_Set_Pixel(4, 7, 1, R, G, B);
 
Cube_Set_Pixel(5, 0, 1, R, G, B);
Cube_Set_Pixel(5, 1, 0, R, G, B);
Cube_Set_Pixel(5, 0, 6, R, G, B);
Cube_Set_Pixel(5, 1, 7, R, G, B);
Cube_Set_Pixel(5, 6, 7, R, G, B);
Cube_Set_Pixel(5, 7, 6, R, G, B);
Cube_Set_Pixel(5, 6, 0, R, G, B);
Cube_Set_Pixel(5, 7, 1, R, G, B);
 
 
Cube_Set_Pixel(6, 0, 2, R, G, B);
Cube_Set_Pixel(6, 0, 3, R, G, B);
Cube_Set_Pixel(6, 0, 4, R, G, B);
Cube_Set_Pixel(6, 0, 5, R, G, B);
Cube_Set_Pixel(6, 1, 6, R, G, B);
Cube_Set_Pixel(6, 2, 7, R, G, B);
Cube_Set_Pixel(6, 3, 7, R, G, B);
Cube_Set_Pixel(6, 4, 7, R, G, B);
Cube_Set_Pixel(6, 5, 7, R, G, B);
Cube_Set_Pixel(6, 6, 6, R, G, B);
Cube_Set_Pixel(6, 7, 5, R, G, B);
Cube_Set_Pixel(6, 7, 4, R, G, B);
Cube_Set_Pixel(6, 7, 3, R, G, B);
Cube_Set_Pixel(6, 7, 2, R, G, B);
Cube_Set_Pixel(6, 6, 1, R, G, B);
Cube_Set_Pixel(6, 5, 0, R, G, B);
Cube_Set_Pixel(6, 4, 0, R, G, B);
Cube_Set_Pixel(6, 3, 0, R, G, B);
Cube_Set_Pixel(6, 2, 0, R, G, B);
Cube_Set_Pixel(6, 1, 1, R, G, B);
 
Cube_Set_Pixel(7, 1, 5, R, G, B);
Cube_Set_Pixel(7, 1, 4, R, G, B);
Cube_Set_Pixel(7, 1, 3, R, G, B);
Cube_Set_Pixel(7, 1, 2, R, G, B);
Cube_Set_Pixel(7, 6, 5, R, G, B);
Cube_Set_Pixel(7, 6, 4, R, G, B);
Cube_Set_Pixel(7, 6, 3, R, G, B);
Cube_Set_Pixel(7, 6, 2, R, G, B);
Cube_Set_Pixel(7, 2, 6, R, G, B);
Cube_Set_Pixel(7, 3, 6, R, G, B);
Cube_Set_Pixel(7, 4, 6, R, G, B);
Cube_Set_Pixel(7, 5, 6, R, G, B);
Cube_Set_Pixel(7, 2, 1, R, G, B);
Cube_Set_Pixel(7, 3, 1, R, G, B);
Cube_Set_Pixel(7, 4, 1, R, G, B);
Cube_Set_Pixel(7, 5, 1, R, G, B);
break;
case 6:
Cube_Set_Pixel(0, 0, 2, R, G, B);
Cube_Set_Pixel(0, 0, 3, R, G, B);
Cube_Set_Pixel(0, 0, 4, R, G, B);
Cube_Set_Pixel(0, 0, 5, R, G, B);
Cube_Set_Pixel(0, 1, 1, R, G, B);
Cube_Set_Pixel(0, 1, 6, R, G, B);
Cube_Set_Pixel(0, 2, 0, R, G, B);
Cube_Set_Pixel(0, 2, 7, R, G, B);
Cube_Set_Pixel(0, 3, 0, R, G, B);
Cube_Set_Pixel(0, 3, 7, R, G, B);
Cube_Set_Pixel(0, 4, 0, R, G, B);
Cube_Set_Pixel(0, 4, 7, R, G, B);
Cube_Set_Pixel(0, 5, 0, R, G, B);
Cube_Set_Pixel(0, 5, 7, R, G, B);
Cube_Set_Pixel(0, 6, 6, R, G, B);
Cube_Set_Pixel(0, 6, 1, R, G, B);
Cube_Set_Pixel(0, 7, 2, R, G, B);
Cube_Set_Pixel(0, 7, 3, R, G, B);
Cube_Set_Pixel(0, 7, 4, R, G, B);
Cube_Set_Pixel(0, 7, 5, R, G, B);
 
Cube_Set_Pixel(1, 0, 1, R, G, B);
Cube_Set_Pixel(1, 1, 0, R, G, B);
Cube_Set_Pixel(1, 0, 6, R, G, B);
Cube_Set_Pixel(1, 1, 7, R, G, B);
Cube_Set_Pixel(1, 6, 7, R, G, B);
Cube_Set_Pixel(1, 7, 6, R, G, B);
Cube_Set_Pixel(1, 6, 0, R, G, B);
Cube_Set_Pixel(1, 7, 1, R, G, B);
 
Cube_Set_Pixel(2, 0, 0, R, G, B);
Cube_Set_Pixel(2, 0, 7, R, G, B);
Cube_Set_Pixel(2, 7, 7, R, G, B);
Cube_Set_Pixel(2, 7, 0, R, G, B);
 
Cube_Set_Pixel(3, 0, 0, R, G, B);
Cube_Set_Pixel(3, 0, 7, R, G, B);
Cube_Set_Pixel(3, 7, 7, R, G, B);
Cube_Set_Pixel(3, 7, 0, R, G, B);
 
Cube_Set_Pixel(4, 0, 0, R, G, B);
Cube_Set_Pixel(4, 0, 7, R, G, B);
Cube_Set_Pixel(4, 7, 7, R, G, B);
Cube_Set_Pixel(4, 7, 0, R, G, B);
 
Cube_Set_Pixel(5, 0, 0, R, G, B);
Cube_Set_Pixel(5, 0, 7, R, G, B);
Cube_Set_Pixel(5, 7, 7, R, G, B);
Cube_Set_Pixel(5, 7, 0, R, G, B);
 
Cube_Set_Pixel(6, 0, 1, R, G, B);
Cube_Set_Pixel(6, 1, 0, R, G, B);
Cube_Set_Pixel(6, 0, 6, R, G, B);
Cube_Set_Pixel(6, 1, 7, R, G, B);
Cube_Set_Pixel(6, 6, 7, R, G, B);
Cube_Set_Pixel(6, 7, 6, R, G, B);
Cube_Set_Pixel(6, 6, 0, R, G, B);
Cube_Set_Pixel(6, 7, 1, R, G, B);
 
Cube_Set_Pixel(7, 0, 2, R, G, B);
Cube_Set_Pixel(7, 0, 3, R, G, B);
Cube_Set_Pixel(7, 0, 4, R, G, B);
Cube_Set_Pixel(7, 0, 5, R, G, B);
Cube_Set_Pixel(7, 1, 1, R, G, B);
Cube_Set_Pixel(7, 1, 6, R, G, B);
Cube_Set_Pixel(7, 2, 0, R, G, B);
Cube_Set_Pixel(7, 2, 7, R, G, B);
Cube_Set_Pixel(7, 3, 0, R, G, B);
Cube_Set_Pixel(7, 3, 7, R, G, B);
Cube_Set_Pixel(7, 4, 0, R, G, B);
Cube_Set_Pixel(7, 4, 7, R, G, B);
Cube_Set_Pixel(7, 5, 0, R, G, B);
Cube_Set_Pixel(7, 5, 7, R, G, B);
Cube_Set_Pixel(7, 6, 6, R, G, B);
Cube_Set_Pixel(7, 6, 1, R, G, B);
Cube_Set_Pixel(7, 7, 2, R, G, B);
Cube_Set_Pixel(7, 7, 3, R, G, B);
Cube_Set_Pixel(7, 7, 4, R, G, B);
Cube_Set_Pixel(7, 7, 5, R, G, B);
break;
case 7:
Cube_Set_Pixel(0, 0, 1, R, G, B);
Cube_Set_Pixel(0, 1, 0, R, G, B);
Cube_Set_Pixel(0, 0, 6, R, G, B);
Cube_Set_Pixel(0, 1, 7, R, G, B);
Cube_Set_Pixel(0, 6, 7, R, G, B);
Cube_Set_Pixel(0, 7, 6, R, G, B);
Cube_Set_Pixel(0, 7, 1, R, G, B);
Cube_Set_Pixel(0, 6, 0, R, G, B);
 
Cube_Set_Pixel(1, 0, 0, R, G, B);
Cube_Set_Pixel(1, 0, 7, R, G, B);
Cube_Set_Pixel(1, 7, 7, R, G, B);
Cube_Set_Pixel(1, 7, 0, R, G, B);
 
Cube_Set_Pixel(6, 0, 0, R, G, B);
Cube_Set_Pixel(6, 0, 7, R, G, B);
Cube_Set_Pixel(6, 7, 7, R, G, B);
Cube_Set_Pixel(6, 7, 0, R, G, B);
 
Cube_Set_Pixel(7, 0, 1, R, G, B);
Cube_Set_Pixel(7, 1, 0, R, G, B);
Cube_Set_Pixel(7, 0, 6, R, G, B);
Cube_Set_Pixel(7, 1, 7, R, G, B);
Cube_Set_Pixel(7, 6, 7, R, G, B);
Cube_Set_Pixel(7, 7, 6, R, G, B);
Cube_Set_Pixel(7, 7, 1, R, G, B);
Cube_Set_Pixel(7, 6, 0, R, G, B);
break;
case 8:
Cube_Set_Pixel(0, 0, 0, R, G, B);
Cube_Set_Pixel(0, 0, 7, R, G, B);
Cube_Set_Pixel(0, 7, 7, R, G, B);
Cube_Set_Pixel(0, 7, 0, R, G, B);
 
Cube_Set_Pixel(7, 0, 0, R, G, B);
Cube_Set_Pixel(7, 0, 7, R, G, B);
Cube_Set_Pixel(7, 7, 7, R, G, B);
Cube_Set_Pixel(7, 7, 0, R, G, B);
break;
default:
break;
}
}
 
void Cube_Set_Shell(uint8_t layer, uint8_t R, uint8_t G, uint8_t B) {
// Sets the specified shell to the specific color
// Shell 0 is the outermost layer, 3 is the innermost cube of pixels
uint8_t i, j, k;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
if ((layer == 0 || layer == 4)&&(i == 0 || i == 7)) {
Cube_Set_Layer(i,R,G,B);
} else if ((layer == 1 || layer == 4)&&(i == 1 || i == 6)) {
for (j = 1; j < CUBE_ROW_COUNT-1; j++)
for (k = 1; k < CUBE_COLUMN_COUNT-1; k++)
Cube_Set_Pixel(i,j,k,R,G,B);
} else if ((layer == 2 || layer == 4)&&(i == 2 || i == 5)) {
for (j = 2; j < CUBE_ROW_COUNT-2; j++)
for (k = 2; k < CUBE_COLUMN_COUNT-2; k++)
Cube_Set_Pixel(i,j,k,R,G,B);
} else if ((layer == 3 || layer == 4)&&(i == 3 || i == 4)) {
for (j = 3; j < CUBE_ROW_COUNT-3; j++)
for (k = 3; k < CUBE_COLUMN_COUNT-3; k++)
Cube_Set_Pixel(i,j,k,R,G,B);
}
 
if ((layer == 0 || layer == 4)&&(i > 0 && i < 8)) {
for (j = 0; j < 8; j++) {
Cube_Set_Pixel(i,j,0,R,G,B);
Cube_Set_Pixel(i,j,7,R,G,B);
Cube_Set_Pixel(i,0,j,R,G,B);
Cube_Set_Pixel(i,7,j,R,G,B);
}
}
if ((layer == 1 || layer == 4)&&(i > 1 && i < 7)) {
for (j = 1; j < 7; j++) {
Cube_Set_Pixel(i,j,1,R,G,B);
Cube_Set_Pixel(i,j,6,R,G,B);
Cube_Set_Pixel(i,1,j,R,G,B);
Cube_Set_Pixel(i,6,j,R,G,B);
}
}
if ((layer == 2 || layer == 4)&&(i > 2 && i < 6)) {
for (j = 2; j < 6; j++) {
Cube_Set_Pixel(i,j,2,R,G,B);
Cube_Set_Pixel(i,j,5,R,G,B);
Cube_Set_Pixel(i,2,j,R,G,B);
Cube_Set_Pixel(i,5,j,R,G,B);
}
}
}
}
 
void Cube_Rotate_Shell(uint8_t shell, uint8_t direction) {
// Shell is the layer to rotate, with the outermost being 0
uint8_t layer;
445,6 → 1137,103
}
}
 
void Cube_Shift_Row(uint8_t direction) {
// Shifts the display by an entire row
int i, j, k;
if (direction) {
// Shift values in each row by one
for (i = CUBE_ROW_COUNT - 1; i >= 0; i--) { // Row
for (j = 0; j < CUBE_COLUMN_COUNT; j++) {
for (k = 0; k < CUBE_LAYER_COUNT; k++) {
Cube_Move_Pixel(k, i - 1, j, k, i, j);
}
}
}
} else {
for (i = 0; i < CUBE_ROW_COUNT - 1; i++) {
for (j = 0; j < CUBE_COLUMN_COUNT; j++) {
for (k = 0; k < CUBE_LAYER_COUNT; k++) {
Cube_Move_Pixel(k, i + 1, j, k, i, j);
}
}
}
}
}
 
void Cube_Shift_Waterfall(uint8_t *values) {
// Takes an array of 8 values and sets them to the column height
// Each column is set to a manually specified color
uint8_t i, j;
uint8_t update_row = CUBE_ROW_COUNT - 1;
 
// First shift the rows
Cube_Shift_Row(0);
 
// Then update the empty row
for (i = 0; i < CUBE_COLUMN_COUNT; i++) {
for (j = 0; j < CUBE_LAYER_COUNT; j++) {
if (j < values[i]) {
// Specify the color for each column
if (i == 0)
Cube_Set_Pixel(j, update_row, i, RED);
else if (i == 1)
Cube_Set_Pixel(j, update_row, i, ORANGE);
else if (i == 2)
Cube_Set_Pixel(j, update_row, i, YELLOW);
else if (i == 3)
Cube_Set_Pixel(j, update_row, i, GREEN);
else if (i == 4)
Cube_Set_Pixel(j, update_row, i, TEAL);
else if (i == 5)
Cube_Set_Pixel(j, update_row, i, BLUE);
else if (i == 6)
Cube_Set_Pixel(j, update_row, i, PURPLE);
else
Cube_Set_Pixel(j, update_row, i, WHITE);
} else {
Cube_Set_Pixel(j, update_row, i, CLEAR);
}
}
}
}
 
void Cube_Shift_Waterfall2(uint8_t *values) {
// Takes an array of 8 values and sets them to the column height
// Each layer is set to a manually specified color
uint8_t i, j;
uint8_t update_row = CUBE_ROW_COUNT - 1;
 
// First shift the rows
Cube_Shift_Row(0);
 
// Then update the empty row
for (i = 0; i < CUBE_COLUMN_COUNT; i++) {
for (j = 0; j < CUBE_LAYER_COUNT; j++) {
if (j < values[i]) {
// Specify the color for each layer
if (j == 7)
Cube_Set_Pixel(j, update_row, i, RED);
else if (j == 6)
Cube_Set_Pixel(j, update_row, i, ORANGE);
else if (j == 5)
Cube_Set_Pixel(j, update_row, i, YELLOW);
else if (j == 4)
Cube_Set_Pixel(j, update_row, i, GREEN);
else if (j == 3)
Cube_Set_Pixel(j, update_row, i, TEAL);
else if (j == 2)
Cube_Set_Pixel(j, update_row, i, BLUE);
else if (j == 1)
Cube_Set_Pixel(j, update_row, i, PURPLE);
else
Cube_Set_Pixel(j, update_row, i, WHITE);
} else {
Cube_Set_Pixel(j, update_row, i, CLEAR);
}
}
}
}
 
///////////////////////////////
// Overlay control functions //
///////////////////////////////
851,36 → 1640,124
uint8_t i,j,k;
uint8_t buffer[2048] = {0};
uint16_t length;
uint16_t index = 1;
 
// Read and process the ethernet packet
if (!ETH_Read_Packet(buffer, &length)) {
// Check the opcode (first byte) to determine what to do
 
if (buffer[0] == 0x1) { // 0x1 - Reset into Ethernet mode
if (buffer[0] == CUBE_ETH_RESET) { // 0x1 - Reset into Ethernet mode
Reset_Board(BOARD_MODE_ETHERNET);
} else if (buffer[0] == 0x2) { // 0x2 - Reset back to idle mode
Reset_Board(BOARD_MODE_IDLE);
} else if (buffer[0] == 0xA) { // 0xA - Clear the entire cube
Cube_Clear();
} else if (buffer[0] == 0xB) { // 0xB - Set the global brightness value
Cube_Write_DCS(buffer[1]);
} else if (buffer[0] == 0xC) { // 0xC - Set the entire cube
if (length == 0x0601) {
} else if (Get_Board_State() == BOARD_MODE_ETHERNET) {
if (buffer[0] == CUBE_EHT_IDLE) { // 0x2 - Reset back to idle mode
Reset_Board(BOARD_MODE_IDLE);
} else if (buffer[0] == CUBE_ETH_CLEAR) { // 0xA
Cube_Clear();
} else if (buffer[0] == CUBE_ETH_DCS) { // 0xB
// Byte 1 = global brightness value
Cube_Write_DCS(buffer[1]);
} else if (buffer[0] == CUBE_ETH_ROTATE) { // 0xC
// Byte 1 = directon to rotate
ClearWDT();
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_COLUMN_COUNT; j++) {
for (k = 0; k < CUBE_ROW_COUNT; k++) {
Cube_Set_Pixel(i, k, j, buffer[index], buffer[index+1], buffer[index+2]);
index = index + 3;
Cube_Rotate(buffer[1]);
} else if (buffer[0] == CUBE_ETH_ROTATE_LAYER) { // 0xD
// Byte 1 = layer to rotate
// Byte 2 = direction to rotate
ClearWDT();
Cube_Rotate_Shell(buffer[1], buffer[2]);
} else if (buffer[0] == CUBE_ETH_WRITE_ALL) { // 0x10
// Byte 1+ = pixel color data (R/G/B)
if (length == 0x0601) {
ClearWDT();
uint16_t index = 1;
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_COLUMN_COUNT; j++) {
for (k = 0; k < CUBE_ROW_COUNT; k++) {
Cube_Set_Pixel(i, k, j, buffer[index], buffer[index+1], buffer[index+2]);
index = index + 3;
}
}
}
}
} else if (buffer[0] == CUBE_ETH_WRITE_PIXEL) { // 0x11
// Byte 1 = row index
// Byte 2 = column index
// Byte 3 = layer index
// Byte 4 = red channel
// Byte 5 = green channel
// Byte 6 = blue channel
ClearWDT();
Cube_Set_Pixel(buffer[3], buffer[1], buffer[2], buffer[4], buffer[5], buffer[6]);
} else if (buffer[0] == CUBE_ETH_WRITE_CHANNEL) { // 0x12
// Byte 1 = color channel, 0 = red, 1 = green, 2 = blue
// Byte 2+ = color data
uint16_t r, g, b;
uint16_t index = 2;
ClearWDT();
if (buffer[1] % 3 == 0) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
// Cube_Get_Pixel(i, j, k, &r, &g, &b);
Cube_Set_Pixel(i, j, k, buffer[index], 0x00, 0x00);
index++;
}
}
}
} else if (buffer[1] % 3 == 1) {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Get_Pixel(i, j, k, &r, &g, &b);
Cube_Set_Pixel(i, j, k, r, buffer[index], b);
index++;
}
}
}
} else {
for (i = 0; i < CUBE_LAYER_COUNT; i++) {
for (j = 0; j < CUBE_ROW_COUNT; j++) {
for (k = 0; k < CUBE_COLUMN_COUNT; k++) {
Cube_Get_Pixel(i, j, k, &r, &g, &b);
Cube_Set_Pixel(i, j, k, r, g, buffer[index]);
index++;
}
}
}
}
} else if (buffer[0] == CUBE_ETH_WRITE_TEXT) { // 0x20
// Byte 1 = length of string
// Byte 2 = red channel
// Byte 3 = green channel
// Byte 4 = blue channel
// Byte 5 = update speed (ms)
// Byte 6+ = text string
if (buffer[1] != 0) {
Cube_Text_Init(&buffer[6], buffer[1], buffer[2], buffer[3], buffer[4]);
 
TIMER4_Stop();
TIMER4_Init(NULL, NULL, &Cube_Text_Interrupt, buffer[5]);
TIMER4_Start();
} else {
Cube_Overlay_Clear();
TIMER4_Stop();
}
} else if (buffer[0] == CUBE_ETH_WATERFALL) { // 0x30
// Byte 1 = height of column 0
// Byte 2 = height of column 1
// Byte 3 = height of column 2
// Byte 4 = height of column 3
// Byte 5 = height of column 4
// Byte 6 = height of column 5
// Byte 7 = height of column 6
// Byte 8 = height of column 7
Cube_Shift_Waterfall(&buffer[1]);
} else if (buffer[0] == CUBE_ETH_SPHERE) { // 0x31
// Byte 1 = layer (0 = innermost)
// Byte 2 = red channel
// Byte 3 = green channel
// Byte 4 = blue channel
Cube_Set_Sphere(buffer[1], buffer[2], buffer[3], buffer[4]);
}
} else if (buffer[0] == 0xD) { // 0xD - Rotate the cube
Cube_Rotate(buffer[1]);
} else if (buffer[0] == 0xE) { // 0xE - Rotate a layer
Cube_Rotate_Shell(buffer[1], buffer[2]);
}
}
}
}
/PIC Stuff/Cerebot_32MX7_LED_Cube/CUBE.h
12,13 → 12,14
#define GCS_LAYER_SIZE (GCS_REG_SIZE*CUBE_ROW_COUNT)
 
// Color Definitions
#define RED 0x08F,0x000,0x000
#define ORANGE 0x08F,0x020,0x000
#define YELLOW 0x08F,0x08F,0x000
#define GREEN 0x000,0x08F,0x000
#define TEAL 0x000,0x08F,0x08F
#define BLUE 0x000,0x000,0x08F
#define PURPLE 0x08F,0x000,0x08F
#define CLEAR 0x000,0x000,0x000
#define RED 0x0FF,0x000,0x000
#define ORANGE 0x0FF,0x040,0x000
#define YELLOW 0x0FF,0x0FF,0x000
#define GREEN 0x000,0x0FF,0x000
#define TEAL 0x000,0x0FF,0x040
#define BLUE 0x000,0x000,0x0FF
#define PURPLE 0x0FF,0x000,0x0FF
#define WHITE 0x0FF,0x0FF,0x0FF
 
// Control Pin Declarations
39,7 → 40,7
#define XBLNK PORTDbits.RD2
 
// String Overlay Buffer Size
#define CUBE_STRING_MAX_LENGTH 32
#define CUBE_STRING_MAX_LENGTH 255
 
// Data Streaming In Buffer Size
#define CUBE_FRAME_BUFFER_SIZE 3000
55,6 → 56,20
#define CUBE_COMMAND_START_TEXT 0x20 // [R, G, B, Char1, Char2, Char3, ...]
#define CUBE_COMMAND_STOP_TEXT 0x21 // (no data)
 
// Ethernet Op-Codes
#define CUBE_ETH_RESET 0x01
#define CUBE_EHT_IDLE 0x02
#define CUBE_ETH_CLEAR 0x0A
#define CUBE_ETH_DCS 0x0B
#define CUBE_ETH_ROTATE 0x0C
#define CUBE_ETH_ROTATE_LAYER 0x0D
#define CUBE_ETH_WRITE_ALL 0x10
#define CUBE_ETH_WRITE_PIXEL 0x11
#define CUBE_ETH_WRITE_CHANNEL 0x12
#define CUBE_ETH_WRITE_TEXT 0x20
#define CUBE_ETH_WATERFALL 0x30
#define CUBE_ETH_SPHERE 0x31
 
typedef enum {
IDLE,
READ_LENGTH_MSB,
101,12 → 116,20
void Cube_Clear(void);
void Cube_Set_All(uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Layer(uint8_t layer, uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Row(uint8_t row, uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Column(uint8_t column, uint16_t R, uint16_t G, uint16_t B);
void Cube_Set_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t R, uint16_t G, uint16_t B);
void Cube_Get_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t* R, uint16_t* G, uint16_t* B);
void Cube_Move_Pixel(uint8_t layer1, uint8_t row1, uint8_t column1, uint8_t layer2, uint8_t row2, uint8_t column2);
void Cube_Set_Sphere(uint8_t layer, uint8_t R, uint8_t G, uint8_t B);
void Cube_Set_Shell(uint8_t layer, uint8_t R, uint8_t G, uint8_t B);
void Cube_Rotate_Shell(uint8_t shell, uint8_t direction);
void Cube_Rotate(uint8_t direction);
void Cube_Shift_Row(uint8_t direction);
 
void Cube_Shift_Waterfall(uint8_t *values);
void Cube_Shift_Waterfall2(uint8_t *values);
 
// Overlay control functions
void Cube_Overlay_Clear(void);
void Cube_Overlay_Set_Pixel(uint8_t layer, uint8_t row, uint8_t column, uint16_t R, uint16_t G, uint16_t B);
/PIC Stuff/Cerebot_32MX7_LED_Cube/ETHERNET.c
311,10 → 311,12
// uint32_t value = ETHIRQ;
if (ETHIRQbits.TXBUSE) {
// TX bus error, something -should- be done
Reset_Board(BOARD_MODE_IDLE);
ETHIRQbits.TXBUSE = 0;
}
if (ETHIRQbits.RXBUSE) {
// RX bus error, something -should- be done
Reset_Board(BOARD_MODE_IDLE);
ETHIRQbits.RXBUSE = 0;
}
if (ETHIRQbits.RXDONE) {
340,11 → 342,13
if (ETHIRQbits.RXBUFNA) {
// This is a serious error!
// TODO: handle this
Reset_Board(BOARD_MODE_IDLE);
ETHIRQbits.RXBUFNA = 0;
}
if (ETHIRQbits.RXOVFLW) {
// This is a serious error!
// TODO: handle this
Reset_Board(BOARD_MODE_IDLE);
ETHIRQbits.RXOVFLW = 0;
}
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/ETHERNET.h
2,7 → 2,7
#define ETHERNET_H
 
#define ETH_TX_DESCRIPTOR_COUNT 2
#define ETH_RX_DESCRIPTOR_COUNT 2
#define ETH_RX_DESCRIPTOR_COUNT 6
#define ETH_TX_ED_BUFFER_SIZE 2032
#define ETH_RX_ED_BUFFER_SIZE 2032
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/TIMER4.c
44,7 → 44,8
 
void __ISR(_TIMER_4_VECTOR, ipl4) __TIMER_4_Interrupt_Handler(void) {
// Call the saved callback function
(*timer_data_ptr->callback_function_1)();
if (timer_data_ptr->callback_function_1 != NULL)
(*timer_data_ptr->callback_function_1)();
 
if (timer_data_ptr->divider != 0 && timer_data_ptr->callback_function_2 != NULL) {
if (timer_data_ptr->count == timer_data_ptr->divider) {
/PIC Stuff/Cerebot_32MX7_LED_Cube/defines.h
8,8 → 8,8
#include <stdint.h>
 
// Uncomment ONE of the following:
#define CEREBOT_32MX7
// #define CEREBOT_MX7CK
//#define CEREBOT_32MX7
#define CEREBOT_MX7CK
 
// Power supply must be 5V for proper operation of the board!
 
/PIC Stuff/Cerebot_32MX7_LED_Cube/main.c
182,7 → 182,7
 
// Start the controller polling and overlay rotation interrupt
TIMER4_DATA timer_4_data;
TIMER4_Init(&timer_4_data, &Controller_Update, NULL, 0);
TIMER4_Init(&timer_4_data, NULL, NULL, 0);
 
// Process button inputs
BTN_DATA btn_data;
193,8 → 193,10
Controller_Init(&ctrl_data, NULL);
 
// Initialize the Ethernet module
ETH_DATA eth_data;
ETH_Init(&eth_data, NULL, &Cube_Ethernet_Frame_In);
if (op_state == BOARD_MODE_ETHERNET) {
ETH_DATA eth_data;
ETH_Init(&eth_data, NULL, &Cube_Ethernet_Frame_In);
}
SNAKE_DATA snake_data;
TRON_DATA tron_data;
201,12 → 203,11
 
PWM2_Start();
TIMER5_Start();
TIMER4_Start();
/* -------------------- END OF INITIALIZATION -------------------- */
/* ------------------------ BEGIN DISPLAY ------------------------ */
 
// Figure out what state to go into here
// Figure out what to do at this point (depending on current state)
switch (op_state) {
case BOARD_MODE_IDLE:
Idle_Animation_Sequence();
213,11 → 214,15
break;
case BOARD_MODE_SNAKE:;
Controller_Init(&ctrl_data, &Snake_Update_Direction);
TIMER4_Init(NULL, &Controller_Update, NULL, 0);
TIMER4_Start();
Snake_Init(&snake_data);
Snake_Main();
break;
case BOARD_MODE_TRON:
Controller_Init(&ctrl_data, &Tron_Update_Direction);
TIMER4_Init(NULL, &Controller_Update, NULL, 0);
TIMER4_Start();
Tron_Init(&tron_data);
Tron_Main();
break;
230,7 → 235,6
}
 
void Idle_Animation_Sequence(void) {
Delay_MS(250);
 
// Cube_Set_All(RED);
// Delay_MS(2000);
247,7 → 251,7
 
// Start the scrolling text
TIMER4_Stop();
TIMER4_Init(NULL, &Controller_Update, &Cube_Text_Interrupt, 100);
TIMER4_Init(NULL, NULL, &Cube_Text_Interrupt, 100);
// TIMER4_Start();
 
// int8_t start_text[] = "Cube Initialized\r\n";
259,6 → 263,22
 
// Loop through some preset animations
while(1) {
 
Animation_Sawtooth(100);
Animation_Sawtooth(100);
Animation_Sawtooth(100);
Animation_Sphere(100);
Animation_Sphere(100);
Animation_Sphere(100);
Animation_Sphere(100);
Animation_Wave1(100);
Animation_Wave1(100);
Animation_Wave1(100);
Animation_Wave1(100);
Animation_Wave2(100);
Animation_Wave2(100);
Animation_Wave2(100);
Animation_Wave2(100);
// Animation_Solid_Colors(300);
// Animation_Layer_Alternate(300);
// Animation_Pixel_Alternate(200);
265,14 → 285,21
// Animation_Full_Color_Sweep(1000);
Animation_Row_Column_Sweep(40);
Animation_Row_Column_Sweep(40);
Animation_Row_Column_Sweep(40);
Animation_Cube_In_Cube(300);
Animation_Cube_In_Cube(300);
Animation_Cube_In_Cube(300);
Animation_Double_Rotation(40);
Animation_Double_Rotation(40);
Animation_Double_Rotation(40);
// Animation_Pseudo_Random_Colors(300);
Animation_Double_Rotation(30);
Animation_Double_Rotation(30);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
Animation_Pseudo_Random_Colors(300);
// Animation_Random_Colors(300);
 
// ClearWDT(); // Clear the WDT if we dont want the board to reset
279,34 → 306,50
}
}
 
// Function call on button 1 press to change refresh rate
// Function call on button 1 press to change cube operation
void BTN1_Interrupt(void) {
static uint8_t state;
state = (state == 4) ? 0 : state + 1;
TIMER5_Stop();
switch (state) {
case 0:
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
switch (op_state) {
case BOARD_MODE_IDLE:
Reset_Board(BOARD_MODE_SNAKE);
break;
case 1:
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2083); // 60Hz
case BOARD_MODE_SNAKE:
Reset_Board(BOARD_MODE_TRON);
break;
case 2:
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 4166); // 30Hz
case BOARD_MODE_TRON:
Reset_Board(BOARD_MODE_ETHERNET);
break;
case 3:
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 12498); // 10Hz
case BOARD_MODE_ETHERNET:
Reset_Board(BOARD_MODE_IDLE);
break;
case 4:
TIMER5_Init(NULL, &Cube_Timer_Interrupt, 24996); // 5Hz
break;
}
TIMER5_Start();
 
// Code to change refresh rate on button press
// static uint8_t state;
// state = (state == 4) ? 0 : state + 1;
// TIMER5_Stop();
// switch (state) {
// case 0:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
// break;
// case 1:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2083); // 60Hz
// break;
// case 2:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 4166); // 30Hz
// break;
// case 3:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 12498); // 10Hz
// break;
// case 4:
// TIMER5_Init(NULL, &Cube_Timer_Interrupt, 24996); // 5Hz
// break;
// }
// TIMER5_Start();
}
 
// Function call on button 2 press to change brightness
void BTN2_Interrupt(void) {
static uint8_t state;
static uint8_t state = 6;
state = (state == 6) ? 0 : state + 1;
TIMER5_Stop();
Delay_MS(1); // Need to wait for all SPI writes to complete
/PIC Stuff/Cerebot_32MX7_LED_Cube/nbproject/Makefile-genesis.properties
1,5 → 1,5
#
#Wed Jan 29 14:42:18 EST 2014
#Fri Feb 07 16:03:16 EST 2014
default.com-microchip-mplab-nbide-toolchainXC32-XC32LanguageToolchain.md5=83f4565fa27ad9b8015f63d69ef74f66
default.languagetoolchain.dir=C\:\\Program Files (x86)\\Microchip\\xc32\\v1.31\\bin
com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=1f98a0eed69cb2a45c12981fa9470927
/PIC Stuff/Cerebot_32MX7_LED_Cube/nbproject/private/configurations.xml
4,7 → 4,7
<defaultConf>0</defaultConf>
<confs>
<conf name="default" type="2">
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>8108:=&lt;rev>0002:=&lt;man>Digilent:=&lt;prod>Cerebot 32MX7:=&lt;sn>D370400:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<platformToolSN>:=MPLABComm-USB-Microchip:=&lt;vid>04D8:=&lt;pid>8108:=&lt;rev>0002:=&lt;man>Digilent:=&lt;prod>CerebotMX7CK:=&lt;sn>D459520:=&lt;drv>x:=&lt;xpt>h:=end</platformToolSN>
<languageToolchainDir>C:\Program Files (x86)\Microchip\xc32\v1.31\bin</languageToolchainDir>
<mdbdebugger version="1">
<placeholder1>place holder 1</placeholder1>