1

I'm trying to get my LED matrix to run Conway's Game of Life. After 4 different pin configurations, I've finally been able to run a separate test code, that lights all the LED's in order, and then turns them off in order (Code Below). I've written the entirety of GoL in C#, but the Arduino language is just different enough to where I can write sort of ok in it, but not enough to understand what's going wrong. I got a Game of Life code from here and it won't even light my LEDs, or when it does, it's incredibly dim, unlike my test code. I'll show my pin layout in the code. I've tried changing the pins in the GoL code, copying the setup from one to the other, and but for the life of me, I can't seem to figure out why one would light up the LED's without a hitch, and the other is struggling. Can anybody see the changes I'd need to make that would make the GoL code at that link, work like this test code?

Here's my Test code that works fine:

int speed = 4; //the delay time in milliseconds

int pauseDelay = 1;    //the number of milliseconds to display each scanned line

//Pin Definitions
int rowA[] = {14,15,16,17,2,3,4,5};          //An Array defining which pin each row is attached to
                                     //(rows are common anode (drive HIGH))
int colA[] = {6,7,8,9,10,11,12,13};  //An Array defining which pin each column is attached to
                                     //(columns are common cathode (drive LOW))

//The array used to hold a bitmap of the display 
//(if you wish to do something other than scrolling marque change the data in this
//variable then display)
byte data[] = {0,0,0,0,0,0,0,0};    


//Setup runs once when power is applied
void setup()
{ 
  Serial.begin(9600);         //Open the Serial port for debugging
  for(int i = 0; i <8; i++){  //Set the 16 pins used to control the array as OUTPUTs
    pinMode(rowA[i], OUTPUT);
    pinMode(colA[i], OUTPUT);
  }
}

//repeats   
void loop()
{
 //Example #1 - test pattern
 //Run a small test program which lights up each light in time
  test();

 //Example #2 - static image
 //Display a defined bitmap
/* 
  data[0] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)
  data[1] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)
  data[2] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)
  data[3] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)
  data[4] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)
  data[5] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)
  data[6] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)  
  data[7] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)  
  showSprite(speed);
*/ 
 }

//An array to store power values to act as bit masks
const int powers[] = {1,2,4,8,16,32,64,128};

//Runs a pattern where each LED is lit one after another
void test(){
  for(int i = 0; i < 8; i++){
for(int ii = 0; ii< 8; ii++){
data[i] = data[i]+ powers[ii];   //Goes through each row of lights lighting each column one after another
showSprite(speed);
}
  }

  for(int i = 0; i < 8; i++){
   for(int ii = 0; ii< 8; ii++){
data[i] = data[i] - powers[ii];   //Goes through each row of lights turning off each column one after another
   showSprite(speed);
    }
  }  
}

void showSprite(int speed2){
 for(int iii = 0; iii < speed2; iii++){                 //show the current frame speed2 times
  for(int column = 0; column < 8; column++){            //iterate through each column
       for(int i = 0; i < 8; i++){                          
           digitalWrite(rowA[i], LOW);                      //turn off all row pins  
   }
   for(int i = 0; i < 8; i++){ //Set only the one pin
     if(i == column){     digitalWrite(colA[i], LOW);}  //turns the current row on
     else{                digitalWrite(colA[i], HIGH); }//turns the rest of the rows off
   }

   for(int row = 0; row < 8; row++){                    //iterate through each pixel in the current column
    int bit = (data[column] >> row) & 1;
    if(bit == 1){ 
       digitalWrite(rowA[row], HIGH);                   //if the bit in the data array is set turn the LED on
    }

   }
   delay(pauseDelay);                       //leave the column on for pauseDelay microseconds (too high a delay causes flicker)
  } 
 }
}

1 Answer 1

2

I ended up using a different PIN layout, and the GoL code had the pins As anodes where they were Cathodes in the other code. Switched rows pins to Columns pins in the code and Problem solved.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.