Group LL Chapter 5
Group LL Chapter 5
#include <SPI.h>
#define XAXIS 0
#define YAXIS 1
#define ZAXIS 2
#define POS_X 0
#define NEG_X 1
#define POS_Z 2
#define NEG_Z 3
#define POS_Y 4
#define NEG_Y 5
#define BUTTON_PIN 8
#define RED_LED 5
#define GREEN_LED 7
#define TOTAL_EFFECTS 8
#define RAIN 0
#define PLANE_BOING 1
#define SEND_VOXELS 2
#define WOOP_WOOP 3
#define CUBE_JUMP 4
#define GLOW 5
30
#define TEXT 6
#define LIT 7
#define GLOW_TIME 8
uint8_t characters[10][8] = {
};
31
uint8_t cube[8][8];
uint8_t currentEffect;
uint16_t timer;
uint64_t randomTimer;
bool loading;
void setup() {
loading = true;
randomTimer = 0;
currentEffect = RAIN;
SPI.begin();
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
randomSeed(analogRead(0));
32
digitalWrite(GREEN_LED, HIGH);
void loop() {
randomTimer++;
if (digitalRead(BUTTON_PIN) == LOW) {
clearCube();
loading = true;
timer = 0;
currentEffect++;
if (currentEffect == TOTAL_EFFECTS) {
currentEffect = 0;
randomSeed(randomTimer);
randomTimer = 0;
digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, LOW);
delay(500);
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
}
33
switch (currentEffect) {
default: rain();
renderCube();
void renderCube() {
digitalWrite(SS, LOW);
SPI.transfer(cube[i][j]);
34
digitalWrite(SS, HIGH);
void rain() {
if (loading) {
clearCube();
loading = false;
timer++;
timer = 0;
shift(NEG_Y);
uint8_t planePosition = 0;
uint8_t planeDirection = 0;
void planeBoing() {
if (loading) {
clearCube();
planePosition = random(0, 2) * 7;
setPlane(axis, planePosition);
if (axis == XAXIS) {
if (planePosition == 0) {
planeDirection = POS_X;
} else {
planeDirection = NEG_X;
if (planePosition == 0) {
planeDirection = POS_Y;
} else {
planeDirection = NEG_Y;
if (planePosition == 0) {
planeDirection = POS_Z;
} else {
planeDirection = NEG_Z;
36
timer = 0;
looped = false;
loading = false;
timer++;
timer = 0;
shift(planeDirection);
if (planeDirection % 2 == 0) {
planePosition++;
if (planePosition == 7) {
if (looped) {
loading = true;
} else {
planeDirection++;
looped = true;
} else {
planePosition--;
if (planePosition == 0) {
37
if (looped) {
loading = true;
} else {
planeDirection--;
looped = true;
uint8_t selX = 0;
uint8_t selY = 0;
uint8_t selZ = 0;
uint8_t sendDirection = 0;
void sendVoxels() {
if (loading) {
clearCube();
}
38
loading = false;
timer++;
timer = 0;
if (!sending) {
if (getVoxel(selX, 0, selZ)) {
selY = 0;
sendDirection = POS_Y;
selY = 7;
sendDirection = NEG_Y;
sending = true;
} else {
if (sendDirection == POS_Y) {
selY++;
if (selY == 7) {
39
sending = false;
} else {
selY--;
if (selY == 0) {
sending = false;
uint8_t cubeSize = 0;
void woopWoop() {
if (loading) {
clearCube();
cubeSize = 2;
cubeExpanding = true;
loading = false;
}
40
timer++;
timer = 0;
if (cubeExpanding) {
cubeSize += 2;
if (cubeSize == 8) {
cubeExpanding = false;
} else {
cubeSize -= 2;
if (cubeSize == 2) {
cubeExpanding = true;
clearCube();
uint8_t xPos;
uint8_t yPos;
uint8_t zPos;
41
void cubeJump() {
if (loading) {
clearCube();
xPos = random(0, 2) * 7;
yPos = random(0, 2) * 7;
zPos = random(0, 2) * 7;
cubeSize = 8;
cubeExpanding = false;
loading = false;
timer++;
timer = 0;
clearCube();
os == 7) {
if (cubeExpanding) {
cubeSize++;
if (cubeSize == 8) {
cubeExpanding = false;
xPos = random(0, 2) * 7;
yPos = random(0, 2) * 7;
zPos = random(0, 2) * 7;
} else {
cubeSize--;
if (cubeSize == 1) {
cubeExpanding = true;
}
43
bool glowing;
uint16_t glowCount = 0;
void glow() {
if (loading) {
clearCube();
glowCount = 0;
glowing = true;
loading = false;
timer++;
timer = 0;
if (glowing) {
do {
glowCount++;
lightCube();
glowCount++;
} else {
glowing = false;
glowCount = 0;
} else {
do {
glowCount++;
} else {
clearCube();
glowing = true;
glowCount = 0;
}
45
uint8_t charCounter = 0;
uint8_t charPosition = 0;
if (loading) {
clearCube();
charPosition = -1;
charCounter = 0;
loading = false;
timer++;
timer = 0;
shift(NEG_Z);
charPosition++;
if (charPosition == 7) {
charCounter++;
charCounter = 0;
}
46
charPosition = 0;
if (charPosition == 0) {
void lit() {
if (loading) {
clearCube();
cube[i][j] = 0xFF;
loading = false;
return (cube[7 - y][7 - z] & (0x01 << x)) == (0x01 << x);
if (axis == XAXIS) {
setVoxel(i, j, k);
setVoxel(j, i, k);
setVoxel(j, k, i);
}
48
if (dir == POS_X) {
cube[7][i] = 0;
}
49
cube[0][i] = 0;
cube[y][z - 1] = cube[y][z];
cube[i][7] = 0;
}
50
cube[i][0] = 0;
setVoxel(x, y + i, z);
setVoxel(x + i, y, z);
setVoxel(x, y, z + i);
setVoxel(x + s - 1, y + i, z + s - 1);
setVoxel(x + i, y + s - 1, z + s - 1);
setVoxel(x + s - 1, y + s - 1, z + i);
setVoxel(x + s - 1, y + i, z);
setVoxel(x, y + i, z + s - 1);
setVoxel(x + i, y + s - 1, z);
setVoxel(x + i, y, z + s - 1);
setVoxel(x + s - 1, y, z + i);
setVoxel(x, y + s - 1, z + i);
void lightCube() {
51
cube[i][j] = 0xFF;
void clearCube() {
cube[i][j] = 0;
}
52
o Rain: This effect adds raindrops to the top layer of the cube, and then let fall
down to the bottom layer.
o Plane Boeing: This effect draws a plane along the specified axis then moves it
from position 0 to 7 on the axis and back again. This is very simple , but it
really brings out the depth of the 3d LED cube .This function doesn’t have an
iteration loop .Instead it is called twice for each axis in launch effect.
o Box shrink grow and woop-woop: Effect draws a wireframe box tilling the
entire cube ,and then shrinks it down to one voxel in one 8 corners .We call
this function one time for each of the 8 corners to create an nice effect . Effect
draws a box that starts as a 8*8*8 wireframe box filling the entire cube. It then
shrinks down to a2*2*2 box at the center of the cube.
o The glow time: In an LED cube refers to the duration for which an individual
LED or set of LEDs remains lit during a given cycle or sequence. The glow
time can vary depending on how the cube is programmed .It is often controlled
by the refresh rate and multiplexing technique used in the cube.
o The "clock effect" in an LED cube is a visual representation of time using the
3D arrangement of LEDs. It simulates the passage of time by lighting up
specific LEDs to represent hours, minutes, and possibly seconds, in a dynamic
way. Here are some common ways to create a clock effect in an LED cube.
o The "text effect" in an LED cube refers to the display of scrolling or static text
using the LEDs in a 3D grid. This effect is created by controlling the
individual LEDs to form letters and numbers, which are then displayed in
sequence to give the appearance of moving or stationary text within the cube.
•
53
During the construction and testing of the three by three prototype constructed during
the two semester terms, some lessons were definitely learned , and they were of great help
when starting with the construction of the letter prototypes .For better understanding , the
selection of the parts was discussed first .In Ahmedabad, there is a lack of a full size
specialized electronic store.
Therefore , we learn that all the electronic parts , no matter what simple is, will have
to be order online . The first step into construction was to do holes in two by four piece of
wood to form and hold the square shape of the cube for later place the LED inside the hole
and solder together forming the layers .To do the hole we use a small four volt , quarter
inches screwdriver . We start at the center mark and every time the drill vibrate making the
hole in different position and some of the holes were bigger than the LED due to the
imprecision of the drill.
The lesson learn in this part is to use a more powerful drill , or even better a press drill
,or even better a press drill, with a new drill bit that will not misplace holes . The second step
into the construction was to put the LED’s together .The soldering of the LED have to be my
two people , one person to solder and another person to hold the LED’s on places until cool
down and form a strong connection.
Soldering the different layer was not as show in the instruction video because it hard
to keep the different layer at the same high. We have to find a better way to have the same
high throughout the final eight by eight by eight projects. fter close examination we discover
some cathode was loose and one anode for another layer was loose too. With that fail we
learned the important of having very strong soldering and also to add more wire that way the
cathode will have a ring type path.
There were too many wires and we had to double check for loose connections. For the
final design cables were used to connect between the LED's and LED's drivers. The prototype
helped us to understand in full all the functions of the electronics and the codes providing the
instruction video . After the construction the prototype was left in the locker and the next
week we tried to do more testing but the upper layer did not work.