- Arduino: 1.8.19 (Windows 10), Board: "ATmega328, Yes (UART0), EEPROM retained, Default, 328P / 328PA, BOD 2.7V, LTO disabled, Internal 8 MHz"
- Sketch uses 15180 bytes (46%) of program storage space. Maximum is 32384 bytes.
- Global variables use 65 bytes (3%) of dynamic memory, leaving 1983 bytes for local variables. Maximum is 2048 bytes.
- C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Users\Mike\Documents\Arduino\hardware\MiniCore\avr/avrdude.conf -v -patmega328p -curclock -PCOM1 -b38400 -D -xnometadata -Ueeprom:w:C:\Users\Mike\AppData\Local\Temp\arduino_build_208537/HC4x4x4_Animation.ino.eep:i -Uflash:w:C:\Users\Mike\AppData\Local\Temp\arduino_build_208537/HC4x4x4_Animation.ino.hex:i
- An error occurred while uploading the sketch
- avrdude: Version 6.3-20190619
- Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
- Copyright (c) 2007-2014 Joerg Wunsch
- System wide configuration file is "C:\Users\Mike\Documents\Arduino\hardware\MiniCore\avr/avrdude.conf"
- avrdude: error at C:\Users\Mike\Documents\Arduino\hardware\MiniCore\avr/avrdude.conf:421: syntax error
- avrdude: error reading system wide configuration file "C:\Users\Mike\Documents\Arduino\hardware\MiniCore\avr/avrdude.conf"
- /Codebox]
- Any ideas how to fix this?
- Cheers,
- Mike
This Arduino library is for the Hobby Components range of 4x4x4 LED cube kits. It can be used to create your own cube animations or to restore the default animation supplied with the kit.
This library is compatible with all versions (V1, V.1 & V2) cube kit. See notes about using this library with various versions of the kit.
To upload sketches to your cube you will also need a USB to serial adaptor. If you do not already have an adapter we currently sell two suitable versions:
https://hobbycomponents.com/usb-interfa ... al-adaptor
https://hobbycomponents.com/usb-interfa ... rt-adapter
STEP 1: Installing the Arduino IDE
To use this library you will need to install the Arduino integrated development environment (IDE) which can be freely downloaded from the software section of the Arduino website here:
https://www.arduino.cc/en/software
Arduino IDE Install instructions are available here:
https://www.arduino.cc/en/Guide
STEP 2: Installing the HC4x4x4 library
Download the HC4x4x4 zip file here:
Next open the Arduino IDE and click the Sketch menu option at the top of the IDE window.
In the sketch menu navigate to Include Library->Add .Zip Library
A file navigation window will now open. Navigate to wherever you downloaded the HC4x4x4.zip file , select it and click the open button.
This library should now be automatically added to your Arduino IDE. Alternatively you can just unzip the library into your Arduino library folder usually found in the following location:
On Windows:
My Documents\Arduino\libraries\
On Mac:
Documents/Arduino/libraries/
Linux:
Usually found within the users home area under /Arduino/libraries/
Once the library has been installed you can access the example sketches by clicking the File menu and navigating to Examples->HC4x4x4
STEP 3: Configuring the IDE for your version of cube
Version 2 cube:
Version 2 cubes are supplied pre-flashed with the MiniCore bootloader. You must first add support for this bootloader to your Arduino IDE via the Arduino board manager feature before sketches can be uploaded.
To do this go to the MiniCore github page and follow 'How to install' -> 'Boars manager' section. A direct link to this section is available here:
https://github.com/MCUdude/MiniCore#boa ... stallation
Once you have followed the steps in the link above your Arduino IDE should now have support for the MiniCore bootloader and you can configure the board settings under the 'Tools' menu as follows:
Board: "ATMega328" Clock: "Internal 8MHz" BOD: "BOD 2.7V" EEPROM: "EEPROM Retained" Complier LTO: "LTO Disabled" Variant: This will depend on version of device shipped with your kit but is normally "328P / 328PA" Bootloader: "Yes (UART0)" Port: The COM port of your USB to serial adapter
Version 1 & 1.1 cubes:
Version 1 & 1.1 cubes are currently shipped with the Arduino Nano bootloader installed. To upload sketches configure the board settings under the 'Tools' menu as follows:
Board: "Arduino Nano" Processor: "ATMega328p (old bootloader)" Port: The COM port of your USB to serial adapter
Next you will need tell the library what version of cube you have (library defaults to version 2). To do this you will need to open the version.h file in a text editor and uncomment the version of your cube:
- /****************************************************************************/
- // UNCOMMENT ONE OF THE FOLLOWING DEPENDING ON YOUR CUBE VERSION
- /****************************************************************************/
- #define CUBE_VERSION_1 //<-- Version 1 & 1.1 Users uncomment this line
- //#define CUBE_VERSION_1_NO_XTAL
- //#define CUBE_VERSION_2
- /****************************************************************************/
Using the library:
To use the library include the HC4x4x4.h header file in your sketch, create an instance of the library, and initialise it in the startup() section of your sketch as follows:
- // Step 1: Include the library
- #include "HC4x4x4.h"
- // Step 2: Create an instance of the library
- HC4x4x4 HC4x4x4;
- void setup()
- {
- // Step 3: Initialise the library
- HC4x4x4.init();
- }
- void loop()
- {
- }
HC4x4x4 Library Functions:
HC4x4x4.plot(x, y, z, mode);
Sets the state of one of the cubes LEDS where:
x, y, & z are signed integer values containing the coordinates of the LED.
Valid values are 0 to 3. Note values outside this range are ignored.
mode specifies the state to set the LED to. Valid values for mode are:
ON Turns the LED on
OFF Turns the LED off
INVERT Inverts the current state of the LED
Note if the mode parameter is omitted the LED will be tuned on
Returns: void
HC4x4x4.get(x, y, z);
Gets the current state of the LED where:
x, y, & z are signed integer values containing the coordinates of the LED.
Returns: A boolean value representing the current state of the LED
HC4x4x4.line(x1, y1, z1, x2, y2, z2, mode);
Draws a line of 1 LED thickness in 3d where:
x1, y1, z1 is the x,y,z coordinate of the start of the line
x2, y2, z2 is the x,y,z coordinate of the end of the line
mode specifies the state to set the LED to. Valide values for mode are:
ON Turns the LED on
OFF Turns the LED off
INVERT Inverts the current state of the LED
Note if the mode parameter is omitted the LED will be tuned on
Returns: void
HC4x4x4.printChar(c, col, layer);
Prints an alphanumeric character where:
c is a char variable containing the character to print
col is the column position on the cube from where to start displaying the character from
layer is the z axis layer to print the character on
HC4x4x4.print(*text, col, layer);
Prints a string of text to the cube where:
*text is a pointer to the start of a null terminated character array containing the text
col is the column position on the cube from where to start displaying the text from
layer is the z axis layer to print the text on
HC4x4x4.printScroll(*text, delay, layer);
Automatically scrolls a string of text across the cube where:
*text is a pointer to the start of a null terminated character array containing the text
length is a integer value containing length of the string in bytes
Returns: void
HC4x4x4.cube(x1, y1, z1, x2, y2, z2, solid, mode);
Used to display a 3D cube primitive where:
x1 is the x axis coordinate for the first corner of the cube.
y1 is the y axis coordinate for the first corner of the cube.
z1 is the z axis coordinate for the first corner of the cube.
x2 is the x axis coordinate for the opposite corner of the cube.
y2 is the y axis coordinate for the opposite corner of the cube.
z2 is the z axis coordinate for the opposite corner of the cube.
valid values for x1, y1, z1, x2, y2, z2 are from 0 to 7
solid specifies whether the cube should be drawn solid (filled in) or wire frame */
mode specifies the state to set the LED to. Valid values for mode are:
ON Turns the LED on
OFF Turns the LED off
INVERT Inverts the current state of the LED
Note if the mode parameter is omitted the LED will be tuned on
Returns: void
HC4x4x4.shift(dir);
Shifts the entire grid of LEDs in one direction where:
dir is the direction to shift. Valide values for dir are:
LEFT Shifts all the LEDs +1 position in the x axis
RIGHT Shifts all the LEDs -1 position in the x axis
UP Shifts all the LEDs +1 position in the y axis
DOWN Shifts all the LEDs -1 position in the y axis
FORWARD Shifts all the LEDs +1 position in the z axis
BACKWARD Shifts all the LEDs -1 position in the z axis
Returns: void
HC4x4x4.setDrawDir(dir);
Sets the drawing orientation where:
dir is the required direction. Valid values for dir are
TOP_0
TOP_90
TOP_180
TOP_270
BOTTOM_0
BOTTOM_90
BOTTOM_180
BOTTOM_270
FRONT_0
FRONT_90
FRONT_180
FRONT_270
LEFT_0
LEFT_90
LEFT_180
LEFT_270
BACK_0
BACK_90
BACK_180
BACK_270
RIGHT_0
RIGHT_90
RIGHT_180
RIGHT_270
Returns: void
HC4x4x4.baseLEDs(state);
Turns on or off the base LEDs where:
state is the required state of the LEDs. Valid values for state are
OFF
ON
Returns: void
Note: THIS COMMAND IS NOT SUPPORTED IN V1 & V1.1 CUBES
Example Sketch:
- /* FILE: HC4x4x4_Library_Examples
- DATE: 19/11/21
- VERSION: 1.0
- AUTHOR: Andrew Davies
- 19/11/21 version 1.0: Original version
- */
- #include "HC4x4x4.h"
- // Create an instance of the HC4x4x4 library
- HC4x4x4 HC4x4x4;
- void setup()
- {
- // Initialise the library
- HC4x4x4.init();
- }
- void loop()
- {
- /****************************************************************************/
- // PLOT EXAMPLES
- /****************************************************************************/
- // Turn on LED at x,y,z coordinate 0,0,0
- HC4x4x4.plot(0,0,0, ON);
- delay(4000);
- // Plot across x axis
- HC4x4x4.plot(1,0,0, ON);
- HC4x4x4.plot(2,0,0, ON);
- HC4x4x4.plot(3,0,0, ON);
- delay(4000);
- // Plot across y axis
- HC4x4x4.plot(0,1,0, ON);
- HC4x4x4.plot(0,2,0, ON);
- HC4x4x4.plot(0,3,0, ON);
- delay(4000);
- // Plot across z axis
- HC4x4x4.plot(0,0,1, ON);
- HC4x4x4.plot(0,0,2, ON);
- HC4x4x4.plot(0,0,3, ON);
- delay(4000);
- // Turn off LED at x,y,z coordinate 0,0,0
- HC4x4x4.plot(0,0,0, OFF);
- delay(4000);
- // Toggle the state of the LED at 0,0,0
- for(byte i = 0; i < 10; i++)
- {
- HC4x4x4.plot(0,0,0, INVERT);
- delay(500);
- }
- /****************************************************************************/
- // LINE EXAMPLE
- /****************************************************************************/
- // Draw a line
- HC4x4x4.line(0,0,0, 3,3,3, ON);
- delay(4000);
- /****************************************************************************/
- // CUBE EXAMPLES
- /****************************************************************************/
- // Draw a cube with opposite corners at 1,1,1 & 2,2,2, make it solid (true)
- HC4x4x4.cube(1,1,1, 2,2,2, true);
- delay(4000);
- // Draw a bigger cube but make it hollow
- HC4x4x4.cube(0,0,0, 3,3,3, false);
- delay(4000);
- /****************************************************************************/
- // SHIFT EXAMPLE
- /****************************************************************************/
- // Shift left
- for(byte i = 0; i < 4; i++)
- {
- HC4x4x4.shift(LEFT);
- delay(1000);
- }
- /****************************************************************************/
- /****************************************************************************/
- // TEXT EXAMPLES
- /****************************************************************************/
- // Print an 'A' starting a x axis column 0 and z axis layer 0
- HC4x4x4.print("X", 0, 0);
- delay(4000);
- // Print it on the left of the cube
- HC4x4x4.clear();
- HC4x4x4.setDrawDir(LEFT_0);
- HC4x4x4.print("X", 0, 0);
- delay(4000);
- // Print it on the right of the cube
- HC4x4x4.clear();
- HC4x4x4.setDrawDir(RIGHT_0);
- HC4x4x4.print("X", 0, 0);
- delay(4000);
- // Print it on the right of the cube
- HC4x4x4.clear();
- HC4x4x4.setDrawDir(TOP_0);
- HC4x4x4.print("X", 0, 0);
- delay(4000);
- // Turn off all LEDs and put the reference back to the bottom left corner
- HC4x4x4.clear();
- HC4x4x4.setDrawDir(FRONT_0);
- // Scroll some text with a 200ms delay on z axis layer 0
- HC4x4x4.printScroll("Hello World!", 200, 0);
- delay(4000);
- /****************************************************************************/
- }
Disclaimer: Libraries, example code, and diagrams within this forum thread are provided as an additional free service by Hobby Components and are not sold as part of any product. We do not provide any guarantees or warranties as to their accuracy or fitness for purpose.
Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.