This should hopefully fix it....
It's just the Line() and _Diff() functions that have been modified slightly if you just want to cut and paste them into your current file.
I'll hold off uploading this fix to the library thread for a while just in case..
8x8x8 cube programming
Re: 8x8x8 cube programming
You do not have the required permissions to view the files attached to this post.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.
Re: 8x8x8 cube programming
Thanks Andrew
I have applied the changes to the library and tested it. All OK
Whilst you are tinkering with the Line() function can I suggest another change to allow it to be used to turn off a line of voxels ? I had originally copied the code for the Line function and created a new function named LineOff() but it occurred to me that it would be better implemented as an option of the Line() function so I changed it to this
with a corresponding function prototype in the .h file
These changes do not affect the use of the Line() function but allow a line of voxels to be turned off by calling the Line() function with a seventh parameter of false
I have applied the changes to the library and tested it. All OK
Whilst you are tinkering with the Line() function can I suggest another change to allow it to be used to turn off a line of voxels ? I had originally copied the code for the Line function and created a new function named LineOff() but it occurred to me that it would be better implemented as an option of the Line() function so I changed it to this
- void Line(byte x1, byte y1, byte z1, byte x2, byte y2, byte z2, boolean show = true)
- {
- double stepX, stepY, stepZ;
- byte index;
- if(_Diff(x1, x2) >= _Diff(y1,y2) && _Diff(x1, x2) >= _Diff(z1, z2))
- {
- stepX = 1;
- if(x1 > x2)
- stepX = -1;
- _Diff(x2,x1)? stepY = (double)(y2 - y1)/_Diff(x2,x1) : 0;
- _Diff(x2,x1)? stepZ = (double)(z2 - z1)/_Diff(x2,x1) : 0;
- for(index =0; index <= _Diff(x2,x1); index++)
- {
- if (show)
- {
- SetVoxel((stepX*index) +x1, (stepY*index)+y1, (stepZ*index)+z1);
- }
- else
- {
- ClearVoxel((stepX*index) +x1, (stepY*index)+y1, (stepZ*index)+z1);
- }
- }
- }else if(_Diff(y1, y2) > _Diff(x1,x2) && _Diff(y1,y2) > _Diff(z1, z2))
- {
- stepY = 1;
- if(y1 > y2)
- stepY = -1;
- _Diff(y2,y1)? stepX = (double)(x2 - x1)/_Diff(y2,y1) : 0;
- _Diff(y2,y1)? stepZ = (double)(z2 - z1)/_Diff(y2,y1) : 0;
- for(index =0; index <= _Diff(y2,y1); index++)
- {
- if (show)
- {
- SetVoxel((stepX*index)+x1, (stepY*index)+y1, (stepZ*index)+z1);
- }
- else
- {
- ClearVoxel((stepX*index)+x1, (stepY*index)+y1, (stepZ*index)+z1);
- }
- }
- }else
- {
- stepZ = 1;
- if(z1 > z2)
- stepZ = -1;
- _Diff(z2,z1)? stepX = (double)(x2 - x1)/_Diff(z2,z1) : 0;
- _Diff(z2,z1)? stepY = (double)(y2 - y1)/_Diff(z2,z1) : 0;
- for(index =0; index <= _Diff(z2,z1); index++)
- {
- if (show)
- {
- SetVoxel((stepX*index)+x1, (stepY*index)+y1, (stepZ*index)+z1);
- }
- else
- {
- ClearVoxel((stepX*index)+x1, (stepY*index)+y1, (stepZ*index)+z1);
- }
- }
- }
- }
- void Line(byte x1, byte y1, byte z1, byte x2, byte y2, byte z2, boolean show = true);
Re: 8x8x8 cube programming
Thanks for confirming. I've added a new library function called DrawMode(). This will allow you to do what you need but its far more flexible and is more inline with how our graphics libraries work. It has one parameter which sets one of 3 drawing modes:
DRAWMODE_NORMAL This is the default mode and any of the drawing functions will work as normal in this mode.
DRAWMODE_ERASE When set to this mode any of the drawing functions will turn off LEDs rather than turning them on.
DRAWMODE_INVERT When set to this mode any of the drawing functions will toggle the current state of the LEDs.
With a bit of imagination it should allow for some more types of interesting effects but here's a couple of very basic examples:
This of course can be simplified with the DRAWMODE_INVERT option but it demonstrates the two other modes.
The updated library containing this new function is here:
DRAWMODE_NORMAL This is the default mode and any of the drawing functions will work as normal in this mode.
DRAWMODE_ERASE When set to this mode any of the drawing functions will turn off LEDs rather than turning them on.
DRAWMODE_INVERT When set to this mode any of the drawing functions will toggle the current state of the LEDs.
With a bit of imagination it should allow for some more types of interesting effects but here's a couple of very basic examples:
- void setup()
- {
- CubeInit();
- }
- void loop()
- {
- DrawMode(DRAWMODE_NORMAL);
- Line (0, 0, 0, 7, 0, 0);
- delay(1000);
- DrawMode(DRAWMODE_ERASE);
- Line (0, 0, 0, 7, 0, 0);
- delay(1000);
- }
This of course can be simplified with the DRAWMODE_INVERT option but it demonstrates the two other modes.
- #include "HC8x8x8Cube.h"
- #include "HC8x8x8_Cube_Patterns.h"
- void setup()
- {
- CubeInit();
- Cube(1, 1, 1, 6, 6, 6, 1);
- DrawMode(DRAWMODE_INVERT);
- }
- void loop()
- {
- Cube(2, 2, 2, 5, 5, 5, 1);
- delay(500);
- }
The updated library containing this new function is here:
You do not have the required permissions to view the files attached to this post.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.
Re: 8x8x8 cube programming
Downloaded and installed
A quick example from me
All seems fine thank you
A quick example from me
- #include <HC8x8x8Cube.h>
- void setup()
- {
- CubeInit();
- DrawMode(DRAWMODE_INVERT);
- Cube(0, 0, 0, 7, 7, 7, false);
- Cube(2, 2, 2, 5, 5, 5, false);
- }
- void loop()
- {
- Cube(0, 0, 0, 7, 7, 7, false);
- Cube(2, 2, 2, 5, 5, 5, false);
- Cube(1, 1, 1, 6, 6, 6, false);
- Cube(3, 3, 3, 4, 4, 4, false);
- delay(500);
- }
Re: 8x8x8 cube programming
Great. I'll still hold off uploading V0.3 of the library for the moment though.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.