HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Useful guides, libraries, and example sketches to support our Arduino based products.
andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by andrew » Wed Feb 08, 2017 12:37 pm

Ignore the workaround suggestion in the previous post, I think I've found the issue. It looks like newer versions of the IDE are 'compiling out' the Matrix_Buffer[] array all together. I've added a volatile qualifier to stop it from doing that and it seems to have fixed the problem. I've uploaded a fixed version (V0.2) of the library to the first post. It would be greatly appreciated if someone can confirm it has fixed the problem.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

T3chn0h1ppy
Posts: 5
Joined: Tue Feb 07, 2017 12:21 am

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by T3chn0h1ppy » Wed Feb 08, 2017 9:46 pm

can confirm the new library works. Thanks so much for the attention, my little sketch is working :D

out of curiosity, is there a way to save our sketches as patterns in order to simplify sequences?

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by andrew » Thu Feb 09, 2017 10:48 am

That's great, thanks for confirming the fix.
out of curiosity, is there a way to save our sketches as patterns in order to simplify sequences?
Do you mean some sort of software for generating the patterns? I have come across various windows and browser based software for drawing 3D cube patterns but unfortunately I've found anything that will then save the pattern in the correct format. Maybe this can be a future addition.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

T3chn0h1ppy
Posts: 5
Joined: Tue Feb 07, 2017 12:21 am

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by T3chn0h1ppy » Thu Feb 09, 2017 10:26 pm

No, not really, I guess I'm asking what other coding syntax is available. (I'm a complete noob to arduino). For example where we have a sketch like this

Code: Select all

#include <HC4x4x4Cube.h>
#include <HC4x4x4_Cube_Patterns.h>

/* Set the default speed for all animations in ms */
#define SPEED 50

void setup()
{
  /* Initialise the cube */
  CubeInit();
}


/* Main sketch */
void loop()
{
  /* circle 1 */
  Matrix_Buffer[3] = 0b0000010000100000;
  Matrix_Buffer[2] = 0b1000000000000001;
  Matrix_Buffer[1] = 0b1000000000000001;
  Matrix_Buffer[0] = 0b0000010000100000;
  /* Wait 1 seconds*/
  delay(SPEED);

  /* circle 2 */
  Matrix_Buffer[3] = 0b0000010000100000;
  Matrix_Buffer[2] = 0b0100000000000010;
  Matrix_Buffer[1] = 0b0100000000000010;
  Matrix_Buffer[0] = 0b0000010000100000;
  /* Wait 1 seconds*/
  delay(SPEED);

   /* circle 3 */
  Matrix_Buffer[3] = 0b0000001001000000;
  Matrix_Buffer[2] = 0b0010000000000100;
  Matrix_Buffer[1] = 0b0010000000000100;
  Matrix_Buffer[0] = 0b0000001001000000;
  /* Wait 1 seconds*/
  delay(SPEED);

     /* circle 4 */
  Matrix_Buffer[3] = 0b0000001001000000;
  Matrix_Buffer[2] = 0b0001000000001000;
  Matrix_Buffer[1] = 0b0001000000001000;
  Matrix_Buffer[0] = 0b0000001001000000;
  /* Wait 1 seconds*/
  delay(SPEED);

       /* circle 5 */
  Matrix_Buffer[3] = 0b0000001001000000;
  Matrix_Buffer[2] = 0b0000000110000000;
  Matrix_Buffer[1] = 0b0000000110000000;
  Matrix_Buffer[0] = 0b0000001001000000;
  /* Wait 1 seconds*/
  delay(SPEED);

         /* circle 5 */
  Matrix_Buffer[3] = 0b0000010000100000;
  Matrix_Buffer[2] = 0b0000100000010000;
  Matrix_Buffer[1] = 0b0000100000010000;
  Matrix_Buffer[0] = 0b0000010000100000;
  /* Wait 1 seconds*/
  delay(SPEED);
}
Which does one task and loops it. say I want to switch another set of frames within the same sketch, can I define how many times that loop cycles before it changes to the next set of frames, like you do with your preset patterns. I suppose I'm asking what other commands will work with the cube?

sorry if this is long winded, I'm really enjoying making my cube do new things and want to try and achieve a sequence like the default pattern.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by andrew » Fri Feb 10, 2017 10:30 am

Yes you certainly can. The Arduino IDE that your using to write and upload your code uses the C++ programming language. So you can use all the C++ commands that would normally be available to you via the Arduino IDE in conjunction with cube library. So for instance if you wanted to repeat your pattern a set number of times you could use a FOR loop. For example if you wanted to repeat your first pattern 5 times and your second pattern 3 times you can do this:

Code: Select all

for (int index = 0; index < 5; index++)
{

   *** Put your first pattern in here ***

}


for (int index = 0; index < 3; index++)
{

   *** Put your second pattern in here ***

}
Just by looking at it you may be able to work out how the for loop works but if you just google 'C++ for loop' you should find lots of sites explaining how it works.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

T3chn0h1ppy
Posts: 5
Joined: Tue Feb 07, 2017 12:21 am

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by T3chn0h1ppy » Fri Feb 10, 2017 10:44 pm

Great, good to know.

crash course in c++ then!

would it then be possible to create an arduino library of sketches?

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by andrew » Mon Feb 13, 2017 11:05 am

would it then be possible to create an arduino library of sketches?
I think that would be a bit of an odd thing to do. It would be a library of sketches that would in turn need other libraries. It would get very big very quickly.

The Arduino IDE does however have a very good way of organising sketches. If you've not already found it all your sketches can be found under Flie->Sketchbook for your own sketches, and File->Examples for any of the built-in example sketches, or library example sketches.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

T3chn0h1ppy
Posts: 5
Joined: Tue Feb 07, 2017 12:21 am

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by T3chn0h1ppy » Mon Feb 13, 2017 10:37 pm

Ok, thanks for that. Just eyeing up the default patterns and hoping to create something similar :D

Thanks for all your help, its been illuminating :D

mcai8sh4
Posts: 1
Joined: Tue Jan 29, 2019 3:39 pm

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by mcai8sh4 » Tue Jan 29, 2019 9:08 pm

ok, I'm stumped! I've spent 3 hours trying to get the usb.serial port on my mac, not that I've got that I can't seem to upload any code.
After another few hours of trying.... well, everything I can think of, I've got to the stage where I just get red text from avrdude ...
System wide configuration file is "/Applications/Arduino copy.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
User configuration file is "/Users/mcai8sh4/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port : /dev/cu.usbserial
Using Programmer : arduino
Overriding Baud Rate : 115200

and thats where it just sits.
I've tried a combination of different boards/programmers, and different versions of the arduino program.

Any help would be appreciated.

SpoonUnit
Posts: 1
Joined: Mon May 06, 2019 5:41 pm

Re: HC4x4x4Cube Arduino library for 4x4x4 LED cubes

Post by SpoonUnit » Mon May 06, 2019 8:52 pm

Really enjoyed the build. Finally in the programming section, needed to use ATMega328P (Old Bootloader) with Arduino 1.8.9 in order to get the new code loaded.

Many thanks and here's my pattern for all those following along later who want to add another.

https://pastebin.com/0wFAMzgV

I also designed a 3d printable jig to assist making the LED planes.

https://www.thingiverse.com/thing:3612602

Post Reply

Return to “Arduino”