Charlieplexing CODE

Whats up!
So I'm currently building my first LED cube and decided to go with the Charliecube(4x4x4 RGB).
I have built a few spires already and have tried them. Although not with code.
I have a spire wired up to my UNO and am ready to upload the code. But there seems to be an error that I just cannot see... Would anyone be kind and help me? :slight_smile:

int pins[] = {2, 3, 4, 5};

int del = 400;

void setup() {
}

void loop(){
    testLevels(400);
    delay(1000);
}

void testLevels(int _del)
{
   del = _del;
  setLED(0, 1);
  setLED(1, 2);
  setLED(2, 3);
  setLED(3, 0);
  setLED(0, 2);
  setLED(1, 3);
  setLED(2, 0);
  setLED(3, 1);
  setLED(0, 3);
  setLED(1, 0);
  setLED(2, 1);
  setLED(3, 2);
}

void testRGBbyLevel(int _del)
{
  del = _del;
  setLED(0, 1);
  setLED(0, 2);
  setLED(0, 3);
  setLED(1, 2);
  setLED(1, 3);
  setLED(1, 0);
  setLED(2, 3);
  setLED(2, 0);
  setLED(2, 1);
  setLED(3, 0);
  setLED(3, 1);
  setLED(3, 2);
}

void setLED(unsigned int cathode, unsigned int anode)
{
  if (cathode > 3 || anode > 3)
    return;

  for (int i = 0; i < 4; i++) {
    if (i == cathode) {
      pinMode(pins[i], OUTPUT);
      digitalWrite(pins[i], LOW);
    } else if (i == anode) {
      pinMode(pins[i], OUTPUT);
      digitalWrite(pins[i], HIGH);
    } else {
      pinMode(pins[i], INPUT);
    }
  }
  delay(del);
}

Should mention that I am getting the error: expected unqualified-id before '?' token

LinusRJ:
Should mention that I am getting the error: expected unqualified-id before '?' token

I did not when I 'Verified' it.
Also, you cannot digitalWrite a pin without having made its pinMode an OUTPUT (we do that in setup ( ) ).
Your setup ( ) is empty.

@RP, The OP is setting the pins as outputs, immediately before using digitalWrite(). This is normal when charlieplexing. The technique relies on it. It uses the 3 states: OUTPUT-LOW, OUTPUT-HIGH & INPUT (in which the pin is not actually used as an input, but is high-impedance).

@LinusRJ, I can't see an error either. What line is highlighted in the IDE when you see the error?

PaulRB:
@RP, The OP is setting the pins as outputs, immediately before using digitalWrite(). This is normal when charlieplexing. The technique relies on it. It uses the 3 states: OUTPUT-LOW, OUTPUT-HIGH & INPUT (in which the pin is not actually used as an input, but is high-impedance).

Of course... :roll_eyes: "my bad", man.

(Still, I didn't get the compile error cited.)

Why void testLevels(int _del)?
del is already declared and doesn't change.

Did one c-plex before (dim, vexatious).

Garbage characters at end of file - delete and retype last lines will fix.