Help with RGB Cube Code

I’ve been making a 4x4x4 RGB cube for the past couple of weeks, and am now programming it. I’ve made a working code (which cycles through a program in blue, then red, then green), but the only visible colour at a distance is blue. Once the cube turns red or green, it’s so dim that at first, me and some others thought it turned off.
I’ve uploaded a different code to turn on ALL red LED’s and then all green LEDs and they all light up bright enough, which confirmed the problem was in the coding.
I also changed the blue part of the code to red or green and it was still so dim, it was barely visible.

I’m using an Arduino Mega; there are no shorts; and with other codes for single colours, everything works fine.

Could someone please have a look at my code and tell me why blue is the only light colour.

Many thanks,


_4x4x4_RGB_Cube.ino (55.7 KB)

I have also swapped some blue and red pins in the arduino, and the problem is transferred across the colours, further proving the problem is with the code.

Hi, Harry, why did you start a new topic?

You are only setting the blue led pins to output. The red and green are remaining as inputs. If you don’t set them to be outputs, then when you set them to HIGH, only the Arduino’s internal pull-ups are activated, and only a small current will flow.

You need to make this change:

  // set up LED pins as output (active HIGH)
  for (pin = 0; pin < PLANESIZE; pin++) {
    pinMode( LEDPinB[pin], OUTPUT );
    pinMode( LEDPinR[pin], OUTPUT ); // line added here 
    pinMode( LEDPinG[pin], OUTPUT ); // line added here 

In general, your code needs improving. At the moment, its is basically the same piece of code cut & pasted 3 times over.


This is shorter and should give you 7 colours. I can’t test it, but it compiles for me.

I use Arduino 1.6.5, so I had to change

prog_uchar PROGMEM PatternTable[]


const char PROGMEM PatternTable[]

_4x4x4_RGB_Cube.ino (61 KB)