hlxldb

LED光立方制作全过程(三十五)

0
阅读(2471)

 

Step 55Software: Cube virtual space

Software: Cube virtual space

Software: Cube virtual space

Software: Cube virtual space

Software: Cube virtual space

Software: Cube virtual space

Software: Cube virtual space

 

Now that we have a cube buffer and a nice little collection of low level draw functions to populate it, we need to agree on which ways is what, and what is up and what is down ;)

From now on, the native position of the LED cube will be with the cables coming out to the left.

In this orientation, the Y axis goes from left to right. The X axis goes from front to back. The Z axis goes from bottom to top.

Coordinates in this instructable is always represented as x,y,z.

Position 0,0,0 is the bottom left front corner. Position 7,7,7 is the top right back corner.

Why did we use the Y axis for left/right and X for back/front? Shouldn't it be the other way around? Yes, we think so too. We designed the the LED cube to be viewed from the "front" with the cables coming out the back. However, this was quite impractical when having the LED cube on the desk, it was more practical to have the cables coming out the side, and having cube and controller side by side. All the effect functions are designed to be viewed from this orientation.

 

Step 56Software: Effect launcher

Software: Effect launcher

Software: Effect launcher

Software: Effect launcher

We wanted an easy way to run the effects in a fixed order or a random order. The solution was to create an effect launcher function.

launch_effect.c contains the function launch_effect (int effect).

Inside the function there is a switch() statement which calls the appropriate effect functions based on the number launch_effect() was called with.

In launch_effect.h EFFECTS_TOTAL is defined. We set it one number higher than the highest number inside the switch() statement.

Launching the effects one by one is now a simple matter of just looping through the numbers and calling launch_effect(), like this:

while(1)

for (i=0; i < EFFECTS_TOTAL; i++)
{

launch_effect(i);

}

}

This code will loop through all the effects in incremental order forever.
If you want the cube to display effects in a random order, just use the following code:

while (1)
{

launch_effect(rand()%EFFECTS_TOTAL);

}

The %EFFECTS_TOTAL after rand() keeps the random value between 0 and EFFECTS_TOTAL-1.