The libraries developed for the charliecube provide you with a nice set of functions that you can use to draw animations.
drawLed()
This function turns on leds at a specified position. Depending on which color this function turns on different colors of the LED
Valid Permutations
drawLed(color, brightness, x-pos, y-pos, z-pos);
drawLed(color, x-pos, y-pos, z-pos);
Arguments
color: what color the led should be
integer: red, blue, green, purple, yellow, teal, white, off
brightness: what brightness should the led be at
integer 0 1 2 3 4 5 6 7 8 HALF=4 FULL=8
start-x: x coordinate for the starting point
integer 0 1 2 3
start-y: y coordinate for the starting point
integer 0 1 2 3
start-z: z coordinate for the starting point
integer 0 1 2 3
Example
#include "cubeplex.h"
int color = red;
void setup() {
// initilize the cube display
initCube();
// how many secconds until continuePattern is set to false
animationMax = 10;
}
void loop() {
randomLed();
}
void randomLed(){
continuePattern = true;
int animationSpeed = 100;
while (continuePattern) {
int xpos = random(0,4);
int ypos = random(0,4);
int zpos = random(0,4);
drawLed(color,xpos,ypos,zpos);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
}
drawBox()
This function will draw a filled in box of the specified color on the cube
Valid Permutations
drawBox(color, brightness, start-x, start-y, start-z, end-x, end-y, end-z);
drawBox(color, start-x, start-y, start-z, end-x, end-y, end-z);
Arguments
color: what color the led should be
integer red blue green purple yellow teal white off
brightness: what brightness should the led be at
integer 0 1 2 3 4 5 6 7 8 HALF=4 FULL=8
start-x: x coordinate for the starting point
integer 0 1 2 3
start-y: y coordinate for the starting point
integer 0 1 2 3
start-z: z coordinate for the starting point
integer 0 1 2 3
end-x: x coordinate for the ending point
integer 0 1 2 3
end-y: y coordinate for the ending point
integer 0 1 2 3
end-z: z coordinate for the ending point
integer 0 1 2 3
Example
#include "cubeplex.h"
void setup() {
//initilize the cube display
initCube();
// set the number of seconds until continuePattern is set to false
animationMax = 10;
}
void loop() {
bigBlueBox();
tinyGreenBox();
}
void bigBlueBox() {
continuePattern = true;
draw(blue,0,0,0,3,3,3);
flushBuffer();
clearBuffer();
// do nothing while the pattern continues
while(continuePattern);
}
void tinyGreenBox() {
continuePattern = true;
drawBox(green,FULL,1,1,1,2,2,2);
flushBuffer();
clearBuffer();
// loop until the pattern is done
while(continuePattern);
}
drawHollowBox()
This function will draw the walls, celing, and floor of a defined box
Valid Permutations
drawHollowBox(color, brightness, start-x, start-y, start-z, end-x, end-y, end-z);
drawHollowBox(color, start-x, start-y, start-z, end-x, end-y, end-z);
Arguments
color: what color the led should be
integer red blue green purple yellow teal white off
brightness: what brightness should the led be at
integer 0 1 2 3 4 5 6 7 8 HALF=4 FULL=8
start-x: x coordinate for the starting point
integer 0 1 2 3
start-y: y coordinate for the starting point
integer 0 1 2 3
start-z: z coordinate for the starting point
integer 0 1 2 3
end-x: x coordinate for the ending point
integer 0 1 2 3
end-y: y coordinate for the ending point
integer 0 1 2 3
end-z: z coordinate for the ending point
integer 0 1 2 3
Example
#include "cubeplex.h"
int color = red;
void setup() {
// initilize the cube display
initCube();
// set the number of seconds each animation should run for
animationMax = 10;
}
void loop() {
pulsingCube();
}
void pulsingCube() {
continuePattern = true;
int animationSpeed = 100;
while (continuePattern) {
for (int i = 0; i < 4; i++) {
drawHollowBox(color,0,0,0,i,i,i);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
for (int i = 0; i < 4; i++) {
drawHollowBox(color,i,i,i,3,3,3);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
color=nextColor(color);
}
}
drawBoxOutline()
This function will draw edges of a defined box but none of the planes
Valid Permutations
drawBoxOutline(color, brightness, start-x, start-y, start-z, end-x, end-y, end-z);
drawBoxOutline(color, start-x, start-y, start-z, end-x, end-y, end-z);
Arguments
color: what color the led should be
integer red blue green purple yellow teal white off
brightness: what brightness should the led be at
integer 0 1 2 3 4 5 6 7 8 HALF=4 FULL=8
start-x: x coordinate for the starting point
integer 0 1 2 3
start-y: y coordinate for the starting point
integer 0 1 2 3
start-z: z coordinate for the starting point
integer 0 1 2 3
end-x: x coordinate for the ending point
integer 0 1 2 3
end-y: y coordinate for the ending point
integer 0 1 2 3
end-z: z coordinate for the ending point
integer 0 1 2 3
Example
#include "cubeplex.h"
int color = red;
void setup() {
// initilize the cube display
initCube();
// set the number of seconds each animation should run for
animationMax = 10;
}
void loop() {
pulsingCube();
}
void pulsingCube() {
continuePattern = true;
int animationSpeed = 100;
while (continuePattern) {
for (int i = 0; i < 4; i++) {
drawBoxOutline(color,0,0,0,i,i,i);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
for (int i = 0; i < 4; i++) {
drawBoxOutline(color,i,i,i,3,3,3);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
color=nextColor(color);
}
}
drawBoxWalls()
This function will draw the virtical walls and all four sides of a defined box
Valid Permutations
drawBoxWalls(color, brightness, start-x, start-y, start-z, end-x, end-y, end-z);
drawBoxWalls(color, start-x, start-y, start-z, end-x, end-y, end-z);
Arguments
color: what color the led should be
integer red blue green purple yellow teal white off
brightness: what brightness should the led be at
integer 0 1 2 3 4 5 6 7 8 HALF=4 FULL=8
start-x: x coordinate for the starting point
integer 0 1 2 3
start-y: y coordinate for the starting point
integer 0 1 2 3
start-z: z coordinate for the starting point
integer 0 1 2 3
end-x: x coordinate for the ending point
integer 0 1 2 3
end-y: y coordinate for the ending point
integer 0 1 2 3
end-z: z coordinate for the ending point
integer 0 1 2 3
Example
#include "cubeplex.h"
int color = red;
void setup() {
// initilize the cube display
initCube();
// set the number of seconds each animation should run for
animationMax = 10;
}
void loop() {
fountian();
}
void fountian() {
continuePattern = true;
int animationSpeed = 100;
while (continuePattern) {
for (int z = 0; z <= 3; z++) {
drawBoxWalls(color,1,1,z,2,2,z);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
for (int z = 3; z >= 0; z--) {
drawBoxWalls(color,0,0,z,3,3,z);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
color=nextColor(color);
}
}
drawLine()
This function will attempt to draw a line between the two points given. Due to the limited avalibility of pixels the best approximation is chosen for each pixel value
Valid Permutations
drawLine(color, brightness, start-x, start-y, start-z, end-x, end-y, end-z);
drawLine(color, start-x, start-y, start-z, end-x, end-y, end-z);
Arguments
color: what color the led should be
integer red blue green purple yellow teal white off
brightness: what brightness should the led be at
integer 0 1 2 3 4 5 6 7 8 HALF=4 FULL=8
start-x: x coordinate for the starting point
integer 0 1 2 3
start-y: y coordinate for the starting point
integer 0 1 2 3
start-z: z coordinate for the starting point
integer 0 1 2 3
end-x: x coordinate for the ending point
integer 0 1 2 3
end-y: y coordinate for the ending point
integer 0 1 2 3
end-z: z coordinate for the ending point
integer 0 1 2 3
Example
#include "cubeplex.h"
int color = red;
void setup() {
initCube;
animationMax = 10;
}
void loop() {
planarSpin();
}
void planarSpin() {
continuePattern = true;
int animationSpeed = 50;
int spinsPerColor = 5; // a spin is actually half a revolution
while (continuePattern) {
int x = 0;
int y = 0;
for (int i = 0; i < spinsPerColor; i++) {
for (int x = 0; x < 3; x++) {
drawLine(color,x,0,0,3-x,3,0);
drawLine(color,x,0,1,3-x,3,1);
drawLine(color,x,0,2,3-x,3,2);
drawLine(color,x,0,3,3-x,3,3);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
for (int y = 0; y < 3; y++) {
drawLine(color,3,y,0,0,3-y,0);
drawLine(color,3,y,1,0,3-y,1);
drawLine(color,3,y,2,0,3-y,2);
drawLine(color,3,y,3,0,3-y,3);
flushBuffer();
clearBuffer();
delay(animationSpeed);
}
}
color = nextColor(color);
}
}
flushBuffer()
This takes the buffer frame and sets the display memory to match, because the display memory needs to be faster it is split up into two arrays instead of just one. The display frame is actually a ciclic linked list which allows the program to just loop through and turn on the LEDs without the need to check to see if it is at the end of the loop
Valid Permutations
flushBuffer();
Arguments
no arguments
clearBuffer()
This function will clear the buffer that you can write to, this will allow you to draw an eniterly new frame int othe buffer
Valid Permutations
clearBuffer();
Arguments
no arguments