![]() |
MD_Cubo LED Cube Arduino Library
1.1
Library to control LED Cubes
|
#include <MD_Cubo.h>
Public Types | |
enum | axis_t { XAXIS, YAXIS, ZAXIS } |
enum | plane_t { XYPLANE, XZPLANE, YZPLANE } |
Public Member Functions | |
MD_Cubo (uint8_t sizeCube) | |
~MD_Cubo () | |
Methods for hardware control. | |
virtual void | begin (void) |
virtual void | setVoxel (boolean p, uint8_t x, uint8_t y, uint8_t z) |
virtual boolean | getVoxel (uint8_t x, uint8_t y, uint8_t z) |
virtual void | setIntensity (uint8_t intensity) |
virtual void | update () |
virtual void | animate (uint32_t wait=0) |
virtual uint8_t | size (axis_t axis) |
Methods for device-independent graphics. | |
virtual void | clear (boolean p=false) |
virtual void | fillPlane (boolean p, plane_t plane, uint8_t coord) |
virtual void | copyPlane (plane_t plane, uint8_t cordFrom, uint8_t cordTo) |
virtual void | drawLine (boolean p, uint8_t x1, uint8_t y1, uint8_t z1, uint8_t x2, uint8_t y2, uint8_t z2) |
virtual void | drawRPrism (boolean p, uint8_t x, uint8_t y, uint8_t z, int8_t dx, uint8_t dy, uint8_t dz) |
void | drawCube (boolean p, uint8_t x, uint8_t y, uint8_t z, int8_t size) |
Protected Attributes | |
uint8_t | _sizeXaxis |
the number of LEDs on x axis of the cube. Total number of pixels is x*y*z. | |
uint8_t | _sizeYaxis |
the number of LEDs on y axis of the cube. Total number of pixels is x*y*z. | |
uint8_t | _sizeZaxis |
the number of LEDs on z axis of the cube. Total number of pixels is x*y*z. | |
Core object for the MD_Cubo library
enum MD_Cubo::axis_t |
enum MD_Cubo::plane_t |
MD_Cubo::MD_Cubo | ( | uint8_t | sizeCube | ) |
Class Constructor.
Instantiate a new instance of the class. The parameters passed are used to initialise the object. Multiple instances may co-exist provided the virtual cube functions can do so also.
sizeCube | the number of LEDs on each side of the cube. |
MD_Cubo::~MD_Cubo | ( | ) |
Class Destructor.
Released any allocated memory and does the necessary to clean up once the object is no longer required.
|
virtual |
Animate the cube display.
Cubes that need to be refreshed/multiplexed in order to show the display should have the multiplexing code inserted here. The code should be written as a non-blocking state machine that should be executing for wait milliseconds. If wait is zero then one step in the refresh should be executed and the method needs to be invoke often enough to ensure animations are seen to be smooth. This is only implementable in the user derived object, as it is heavily reliant on the hardware configuration.
wait | optional period for this animation to execute before returning. |
Reimplemented in MD_Cubo_ICS595.
|
virtual |
Initialize the object.
Initialise the object data. This needs to be called during setup() to initialise new data for the class that cannot be done during the object creation.
Hardware interfaces implemented in virtual functions should be initialized here.
Reimplemented in MD_Cubo_JC, MD_Cubo_ICS595, and MD_Cubo_72xx.
|
virtual |
Clear the cube.
Set every pixel in the cube to the specificed value (default off). The generic method iterates through all the pixels. A more efficient implementation may be possible by exploiting access to hardware.
p | set ON if true, off if false (default). |
Reimplemented in MD_Cubo_JC, MD_Cubo_ICS595, and MD_Cubo_72xx.
|
virtual |
Copy the specified plane.
One slice of LEDs (a square) is copied from the plane coordinate cordFrom to the plane coordinate cordTo. The coordinate relates to the intersection point between the plane and the axis specified. For example, if plane is XYPLANE, coord is the z value through which the plane passes.
plane | the plane this applies to. One of the plane_t value. |
cordFrom | the source coordinate value. |
cordTo | the destination coordinate value. |
void MD_Cubo::drawCube | ( | boolean | p, |
uint8_t | x, | ||
uint8_t | y, | ||
uint8_t | z, | ||
int8_t | size | ||
) |
Draw the outline of a cube in 3D space.
The cube is a rectangular prism with same dx, dy, dz, so this is a wrapper for the more generic case.
p | pixel value - if false, set the pixel off. If true, set the pixel on. |
x | x coordinate for one corner. |
y | y coordinate for one corner. |
z | z coordinate for one corner. |
size | The size of one side of the cube in pixels. |
|
virtual |
Draw an arbitrary line in 3D space.
The line is drawn from the start to the end coordinates using Bresenham's line drawing algorithm in 3D. The line can be drawn 'on' or 'off' by specifying the pixel value, p.
p | pixel value - if false, set the pixel off. If true, set the pixel on. |
x1 | x coordinate for the start point. |
y1 | y coordinate for the start point. |
z1 | z coordinate for the start point. |
x2 | x coordinate for the end point. |
y2 | y coordinate for the end point. |
z2 | z coordinate for the end point. |
|
virtual |
Draw an arbitrary rectangular prism in 3D space.
The rectangular prism is drawn from the start coordinates with to the diagonally opposite corner in 3D space. The line can be drawn 'on' or 'off' by specifying the pixel value, p. A cube is a rectangular prism with the same dx, dy, dz A rectangle (2D) is a rectangular prism with one of dx, dy or dz set to 0
p | pixel value - if false, set the pixel off. If true, set the pixel on. |
x | x coordinate for one corner. |
y | y coordinate for one corner. |
z | z coordinate for one corner. |
dx | x delta for diagonally opposite point. |
dy | y delta for diagonally opposite point. |
dz | z delta for diagonally opposite point. |
|
virtual |
Fill the specified plane.
One slice of LEDs (a square) is turned on or off at the specified coordinate value. The coordinate relates to the intersection point between the plane and the axis specified. For example, if plane is XYPLANE, coord is the z value through which the plane passes.
p | pixel value - if false, set the pixel off. If true, set the pixel on. |
plane | the plane this applies to. One of the plane_t value. |
coord | axis intersection coordinate value. |
|
virtual |
Get the status of specified pixel in the cube.
This is the most basic graphic function and is necessarily only implementable in the user derived object, as it is heavily related to the hardware configuration. The (x,y,z) coordinate for the pixel needs to be mapped to a device address and on/off value of the pixel returned to the calling program..
x | x coordinate for the pixel. |
y | y coordinate for the pixel. |
z | z coordinate for the pixel. |
Reimplemented in MD_Cubo_JC, MD_Cubo_ICS595, and MD_Cubo_72xx.
|
virtual |
Set the intensity/brightness of the cube.
Set the overall brightness of the cube. This is only implementable in the user derived object, as it is heavily reliant on the hardware configuration.
Brightness is supplied as a number 0 to MAX_INTENSITY (0 is darkest). If the hardware has a different range this will need to be remapped in the user derived object.
intensity | the intensity for the cube (0 .. MAX_INTENSITY). |
Reimplemented in MD_Cubo_JC, and MD_Cubo_72xx.
|
virtual |
Set the specified point in the cube.
This is the most basic graphic function and is necessarily only implementable in the user derived object, as it is heavily related to the hardware configuration. The (x,y,z) coordinate for the pixel needs to be mapped to a device action to turn the pixel on or off.
p | pixel value - if false, set the pixel off. If true, set the pixel on. |
x | x coordinate for the pixel. |
y | y coordinate for the pixel. |
z | z coordinate for the pixel. |
Reimplemented in MD_Cubo_JC, MD_Cubo_ICS595, and MD_Cubo_72xx.
|
virtual |
Return the size of the cube.
Return the number of LED on one side of the cube. Allows high level code to be independent of any size definitions, which are known in in the user derived object, as it is reliant on the hardware configuration.
axis | specifies the axis required, one of the axis_t enumerations |
Reimplemented in MD_Cubo_JC, MD_Cubo_ICS595, and MD_Cubo_72xx.
|
virtual |
Update the cube display.
All cube changes are buffered internally until this method is called, at which time the cube is updated. This is only implementable in the user derived object, as it is heavily reliant on the hardware configuration.
Reimplemented in MD_Cubo_JC, MD_Cubo_ICS595, and MD_Cubo_72xx.