Can't find the bug(s?)

Hello.

I am attempting to program a LED cube, that is controlled by IR.

The cube is 7x7x7.
The column starts at 0. goes to 48. Column 1, 20 and 21 are always HIGH. They are not supposed to always be HIGH.

I would appreciate it if you would take a swift look for any obvious bugs.

I've used the I/O from 0-48, 50, and A0-A6.

The first half of the code:

//////////////////////////////////////////////////////////////////////////////////////////
// A. Slettevold // LED cube // 7x7x7 & 2x2x2 // qb UB // DON't LOOK DIRECTLY AT IT //  //
/////////////////////////////////////// include //////////////////////////////////////////
#include "IRremote.h"                                                                   //
/////////////////////////////////////// konstanter ///////////////////////////////////////
int receiver = 50;
double Kol[49] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48};
byte Lag[7] = {A0, A1, A2, A3, A4, A5, A6};
/////////////////////////////////////// objekter /////////////////////////////////////////
IRrecv irrecv(receiver);
decode_results results;
/////////////////////////////////////// variabler ////////////////////////////////////////
int              SisteIR = 0;
int         TidsVariabel = 95;
//int                Teller = 0;  Not nececary
//int                     x = 0;  Not nececary
//int                     y = 0;  Not nececary
int                 Minne = 0;  //pausing
int             KatalogIR = 0;  //neste/forrige (Next/Past program)
int      TilfeldigProgram = 0;
int  TilfeldigGjentagelse = 0;
int        TilfeldigDelay = 0;
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// setup ////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void setup(){
  //Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(Kol[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], OUTPUT);
  pinMode(Lag[A0, A1, A2, A3, A4, A5, A6], OUTPUT);
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// loop /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void loop(){
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
    //Serial.println(results.value, HEX);
    translateIR();
    irrecv.resume(); // receive the next value
  }
  VisProgram();
  if(KatalogIR == 1){SisteIR--;KatalogIR = 0;}
  if(KatalogIR == 2){SisteIR++;KatalogIR = 0;}
}

//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// translateIR //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void translateIR(){
  switch(results.value){
  case 0xFD10EF:  
    Serial.println(" CH-            "); //ble tilbake i programmer
    SlukkLyset();
    KatalogIR = 1;
    break;

  case 0xFF629D:  
    Serial.println(" CH             "); 
    SlukkLyset();
    SisteIR = 1;
    break;

  case 0xFD50AF:  
    Serial.println(" CH+            "); //ble fram i programmer
    SlukkLyset();
    KatalogIR = 2;
    break;

  case 0xFF22DD:  
    Serial.println(" PREV           "); 
    SlukkLyset();
    SisteIR = 4;
    break;

  case 0xFF02FD:  
    Serial.println(" NEXT           ");
    SlukkLyset();
    SisteIR = 5; 
    break;

  case 0xFDA05F:  
    Serial.println(" PLAY/PAUSE     ");
    if(Minne == 0){Minne = SisteIR;SisteIR = 0;}
    else if(Minne > 0){SisteIR = Minne;Minne = 0;}
    break;

  case 0xFD906F:  
    Serial.println(" VOL-           "); 
    SlukkLyset();
    SisteIR = 7;
    break;

  case 0xFD807F:  
    Serial.println(" VOL+           "); 
    SlukkLyset();
    SisteIR = 8;
    break;

  case 0xFDB04F:  
    Serial.println(" EQ             "); 
    SlukkLyset();
    SisteIR = 9;
    break;

  case 0xFD30CF:  
    Serial.println(" 0              ");
    SlukkLyset();
    SisteIR = 10;
    break;

  case 0xFD609F:  
    Serial.println(" |<<            ");
    if (TidsVariabel >= 92){TidsVariabel = TidsVariabel + 1;}
    if(TidsVariabel <= 91){TidsVariabel = TidsVariabel + 5;}
    if(TidsVariabel >= 100){TidsVariabel = 99;}
    Serial.println(TidsVariabel); 
    break;

  case 0xFD20DF:  
    Serial.println(" >>|            "); 
    if(TidsVariabel >= 92){TidsVariabel = TidsVariabel - 1;}
    if(TidsVariabel <= 91){TidsVariabel = TidsVariabel - 5;}
    if(TidsVariabel < 50){TidsVariabel = 50;}
    Serial.println(TidsVariabel);
    break;

  case 0xFD08F7:  
    Serial.println(" 1              "); 
    SlukkLyset();
    SisteIR = 13;
    break;

  case 0xFD8877:  
    Serial.println(" 2              ");  
    SlukkLyset();
    SisteIR = 14;
    break;

  case 0xFD48B7:  
    Serial.println(" 3              "); 
    SlukkLyset();
    SisteIR = 15;
    break;

  case 0xFD28D7:  
    Serial.println(" 4              "); 
    SlukkLyset();
    SisteIR = 16;
    break;

  case 0xFDA857:  
    Serial.println(" 5              ");
    SlukkLyset();
    SisteIR = 17;
    break;

  case 0xFD6897:  
    Serial.println(" 6              "); 
    SlukkLyset();
    SisteIR = 18;
    break;

  case 0xFD18E7:  
    Serial.println(" 7              "); 
    SlukkLyset();
    SisteIR = 19;
    break;

  case 0xFD9867:  
    Serial.println(" 8              "); 
    SlukkLyset();
    SisteIR = 20;
    break;

  case 0xFD58A7:  
    Serial.println(" 9              "); 
    SlukkLyset();
    SisteIR = 21;
    break;
 default:
 //Serial.println(results.value, HEX);
    break;
    }
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// VisProgram ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void VisProgram(){
  switch(SisteIR){
    case 17:
    Program1(TidsVariabel);
    break;
    case 18:
    LysShow();
    break;
    case 19:
    Program2(TidsVariabel);
    break;
    case 20:
    Program4(TidsVariabel);
    break;
    case 21:
    Program3(TidsVariabel);
    break;
  }
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// TestIRDelay //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void TestIRDelay(int Teller){
  while(Teller < 100){ // Teller < timer
    if (irrecv.decode(&results)){translateIR();break;}
        Teller++;
        if (Teller >= 100){break;}
  }
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// SlukkLyset ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void SlukkLyset(){
  for(int L=0; L<7; L++){digitalWrite(Lag[L], LOW);}
  for(int K=0; K<49; K++){digitalWrite(Kol[K], LOW);}
}

Thank you.

//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// LysShow //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void LysShow(){
  TilfeldigProgram = random(1, 4); //forandre ettersom antall programmer
  TilfeldigGjentagelse = random(1, 10);
  while(TilfeldigGjentagelse < 15){
    TilfeldigDelay = random(80, 100);
    switch(TilfeldigProgram){
      case 1:
      Program1(TilfeldigDelay);
      break;
      case 2:
      Program2(TilfeldigDelay);
      break;
      case 3:
      Program3(TilfeldigDelay);
      break;
      case 4:
      Program4(TilfeldigDelay);
      break;
    }
    TilfeldigGjentagelse++;
  }
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// Program //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
void Program2(int TilfeldigDelay){
    if(SisteIR == 18){TidsVariabel = TilfeldigDelay;}
   /* for(int x=0; x<7; x++){
      digitalWrite(Lag[x], HIGH);
      for(int y=0; y<49; y++){
        digitalWrite(Kol[y], HIGH);
        TestIRDelay(98);
        digitalWrite(Kol[y], LOW);
      }
      digitalWrite(Lag[x], LOW);
    }*/
}
void Program3(int TilfeldigDelay){
    if(SisteIR == 18){TidsVariabel = TilfeldigDelay;}
    /*digitalWrite(Lag[x], HIGH);
    digitalWrite(Kol[y], HIGH);
    
    if(x >= 1){x = 0;}
    else if(x < 0){x = 0;}
    else {x++;}
    
    if(y >= 3){y = 0;}
    else if(y < 0){y = 0;}
    else {y++;}
    
    digitalWrite(Kol[y], LOW);
    digitalWrite(Lag[x], LOW); 
    TestIRDelay(TidsVariabel);*/
}

void Program1(int TilfeldigDelay){
  if(SisteIR == 18){TidsVariabel = TilfeldigDelay;}
  
  
    for(int x=0; x<7; x++){digitalWrite(Lag[x], HIGH);}
      //digitalWrite(Kol[0], HIGH);
      //TestIRDelay(TidsVariabel);
      //digitalWrite(Kol[0], LOW);
    for(int x=0; x<7; x++){digitalWrite(Lag[x], LOW);}
}
/*void Program4(int TilfeldigDelay){
    if(SisteIR == 18){TidsVariabel = TilfeldigDelay;}
      
    for(int x=0; x<7; x++){
    digitalWrite(Lag[x], HIGH);
      for(int y=0; y<49; y++){digitalWrite(Kol[y], HIGH);}
        //TestIRDelay(100);
        delayMicroseconds(1250);
        digitalWrite(Lag[x], LOW); 
      for(int y=0; y<49; y++){digitalWrite(Kol[y], LOW);}
    //digitalWrite(Lag[x], LOW); 
  }
}*/
void Program4(int TilfeldigDelay){
    if(SisteIR == 18){TidsVariabel = TilfeldigDelay;}
  for(int x=0; x<7; x++){  
    digitalWrite(Lag[x], HIGH);
      for(int y=0; y<49; y++){digitalWrite(Kol[y], HIGH);}
        //TestIRDelay(100);
        //delayMicroseconds(1250);
      for(int y=0; y<49; y++){digitalWrite(Kol[y], LOW);}
      digitalWrite(Lag[x], LOW);
  }
}

Far too much code for lazy old me.

Can you focus in on the problem area?

...R

Work on a rewrite - for a cube use a 3d array eg myleds[7][7][7]

Mark

This can't even compile. If it doesn't compile, it does not have bugs, it has syntax errors. What the heck is that array argument to pinMode()?

holmes4:
Work on a rewrite - for a cube use a 3d array eg myleds[7][7][7]

Mark

I have yet to understand how to do that. Once I understand this, I'll go for that.

KeithRB:
This can't even compile. If it doesn't compile, it does not have bugs, it has syntax errors. What the heck is that array argument to pinMode()?

It might be because you do not have the IRremote.h library.

The program compiles, and works- to an extent. It works OK. But three columns are always lit.

Thank you both for your replies.

Robin2:
Far too much code for lazy old me.

Can you focus in on the problem area?

...R

I've tried removing code- until it works, for days. I can't seem to find the area of interest.

There's too much irrelevant code there - I'm not going to trawl through trying to guess which code is executing in your test case. For example, I guess that the IR remote code isn't intended to be directly involved in lighting LEDs.

Write a new sketch which just does the minimum possible work needed to demonstrate the problem. For example, start by turning everything off and see whether the LEDs are actually all turned off. If not, track down which output is in the wrong state and which code is causing it to be in that state.

KeithRB:
This can't even compile. If it doesn't compile, it does not have bugs, it has syntax errors. What the heck is that array argument to pinMode()?

Holy gaffaru!

void setup(){
  //Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  for(int G=0; G<49; G++){pinMode(Kol[G], OUTPUT);}
  pinMode(Lag[A0, A1, A2, A3, A4, A5, A6], OUTPUT);
}

Turns out you spotted the mistake. Thank you very much!
Can I do the same thing with A0-A6?

  1. just look up arrays you can have any number of dimensions you wish.

double Kol[49] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48};

apart from wasting 196 bytes of the 2048 bytes of ram that you have on the UNO what is this intended to do Kol[x]will just give you x, its a total waste! as is your next array!

Mark

void setup(){
  //Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  for(int G=0; G<49; G++){pinMode(Kol[G], OUTPUT);}
  pinMode(Lag[A0, A1, A2, A3, A4, A5, A6], OUTPUT);
}

Turns out you spotted the mistake. Thank you very much!
Can I do the same thing with A0-A6?
[/quote]

void setup(){
//Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
for(int G=0; G<48; G++){pinMode(Kol[G], OUTPUT);}
for(int H=A0; H<A6; H++){pinMode(Kol, OUTPUT);}
}
It's working, at least. The code will be improved. Thank you for the replies.

hint pin A0 is also known as pin 14 on the uno.

Mark

pinMode(Lag[A0, A1, A2, A3, A4, A5, A6], OUTPUT); // lists seven pins
for(int H=A0; H<A6; H++){pinMode(Kol[H], OUTPUT);} // initialises six pins

There is an off-by-one error in one of these versions.

I guess it would compile.

A[0,1,2,3,4]

is not a syntax error, just an unwise use of the comma operator.