OK, here’s the code. The Game of Life code appears to be working OK, and it is displayed correctly in the top row of 4 8x8 displays. I chose to go with four instances of LedControl so that the ripple through would only have to go through four displays across.
This is a work in progress, later I’ll add RTC to the display as well.
// 8x8 Matrix Test
//We always have to include the libraries
#include "LedControl.h"
#include <dht.h>
#include <SPI.h>
/* we always wait a bit between updates of the display */
int delaytime = 2000;
int numarrays = 4;
int indexym1, indexy, indexyp1;
byte aray[1024];
byte newaray[1024];
byte lastaray[1024];
//byte thirdaray[1024];
byte sum = 0;
byte lastsecond = 0;
byte second, minute, hour, ampm, dayOfWeek, dayOfMonth, month, year, f1224, t1, t2, f100, f10, f1;
double lasttemp = 0, currenttemp = 0, humidity = 0;
LedControl lc1=LedControl(12,11,10,numarrays); // These have to be here because of scope
LedControl lc2=LedControl(36,34,9,numarrays);
LedControl lc3=LedControl(32,30,8,numarrays);
LedControl lc4=LedControl(28,27,7,numarrays);
dht DHT; // The DHT22 Temperature Humidity sensor
#define DHT22_PIN 41
void setup()
{
f1224 = 1;
RTC_init_DS3234();
//day(1-31), month(1-12), year(0-99), dayofweek (1-7), ampm (0-1), hour(0-23), minute(0-59), second(0-59), 12/24 hr (0-1)
// Sun = 1 0 = am, 1 = pm 0 = 24 hr.
//SetTimeDate_DS3234(19,12,13,5,1,3,51,30,1);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
for (int i=0;i < numarrays; i++)
{
lc1.shutdown(i,false);
lc2.shutdown(i,false);
lc3.shutdown(i,false);
lc4.shutdown(i,false);
/* Set the brightness to a low values */
lc1.setIntensity(i,1);
lc2.setIntensity(i,1);
lc3.setIntensity(i,1);
lc4.setIntensity(i,1);
/* and clear the display */
lc1.clearDisplay(i);
lc2.clearDisplay(i);
lc3.clearDisplay(i);
lc4.clearDisplay(i);
}
for (int i=0; i < 1024; i++)
{
aray[i] = 0;
newaray[i] = 0;
lastaray[i] = 0;
}
SeedArray();
Display_8x8();
delay(delaytime);
// Serial.begin(9600);
}
void loop()
{
Game_of_Life();
// lc1.clearDisplay(0);
// lc1.clearDisplay(1);
// lc1.clearDisplay(2);
// lc1.clearDisplay(3);
// delay(1000);
// for (int j=0; j<18;j++)
// {
// for (int i=0;i<5;i++)
// {
// lc1.setColumn(0,i,alpha[i+j*5]);
// lc1.setColumn(1,i,alpha[i+j*5]);
// lc1.setColumn(2,i,alpha[i+j*5]);
// }
// delay(1000);
// }
// for (int i=4; i< 7; i++)
// {
// Show_Number(0,i-4,i);
// // Show_DayofWeek(i);
//
// delay(1500);
// }
//for (int i=0;i<8;i++)
// {
// lc2.setColumn(0,i,255);
// lc2.setColumn(1,i,255);
// lc2.setColumn(2,i,255);
// lc2.setColumn(3,i,255);
// }
//delay(1000);
}
void Game_of_Life()
{
for (int y = 1; y <= 30; y++)
{
indexym1 = (y-1) * 32;
indexy = y * 32;
indexyp1 = (y+1) * 32;
for (int x = 1; x <= 30; x++)
{
sum = aray[indexym1+x-1] + aray[indexym1+x] + aray[indexym1+x+1] + aray[indexy+x-1] + aray[indexy+x+1] + aray[indexyp1+x-1] + aray[indexyp1+x] + aray[indexyp1+x+1];
if (aray[indexy+x] == 1)
{
if ((sum < 2) || (sum > 3))
{
newaray[indexy+x] = 0; // LED could be changed here
}
else
{
newaray[indexy+x] = 1;
}
}
else
//if (aray[indexy+x] == 0)
{
if (sum == 3)
{
newaray[indexy+x] = 1; // LED could be changed here
}
else
{
newaray[indexy+x] = 0;
}
}
}
}
CheckState();
Display_8x8();
delay(delaytime);
}
void Display_8x8()
{
for (int i=0;i < numarrays; i++)
{
/* Clear the display */
lc1.clearDisplay(i);
lc2.clearDisplay(i);
lc3.clearDisplay(i);
lc4.clearDisplay(i);
}
for (int y = 0; y < 8; y++) // Only the top 8 rows are checked
{
indexy = y * 32;
for (int x = 0; x < 8; x++)
{
if (aray[indexy+x] == 1)
{
lc1.setLed(0, y, x, true);
}
}
for (int x = 8; x < 16; x++)
{
if (aray[indexy+x] == 1)
{
lc1.setLed(1, y, x-8, true);
}
}
for (int x = 16; x < 24; x++)
{
if (aray[indexy+x] == 1)
{
lc1.setLed(2, y, x-16, true);
}
}
for (int x = 24; x < 32; x++)
{
if (aray[indexy+x] == 1)
{
lc1.setLed(3, y, x-24, true);
}
}
}
for (int y = 8; y < 16; y++) // second eight rows
{
indexy = y * 32;
for (int x = 0; x < 8; x++)
{
if (aray[indexy+x] == 1)
{
lc2.setLed(0, y, x, true);
}
}
for (int x = 8; x < 16; x++)
{
if (aray[indexy+x] == 1)
{
lc2.setLed(1, y, x-8, true);
}
}
for (int x = 16; x < 24; x++)
{
if (aray[indexy+x] == 1)
{
lc2.setLed(2, y, x-16, true);
}
}
for (int x = 24; x < 32; x++)
{
if (aray[indexy+x] == 1)
{
lc2.setLed(3, y, x-24, true);
}
}
}
for (int y = 16; y < 24; y++) // third eight rows
{
indexy = y * 32;
for (int x = 0; x < 8; x++)
{
if (aray[indexy+x] == 1)
{
lc3.setLed(0, y, x, true);
}
}
for (int x = 8; x < 16; x++)
{
if (aray[indexy+x] == 1)
{
lc3.setLed(1, y, x-8, true);
}
}
for (int x = 16; x < 24; x++)
{
if (aray[indexy+x] == 1)
{
lc3.setLed(2, y, x-16, true);
}
}
for (int x = 24; x < 32; x++)
{
if (aray[indexy+x] == 1)
{
lc3.setLed(3, y, x-24, true);
}
}
}
for (int y = 24; y < 32; y++) // fourth eight rows
{
indexy = y * 32;
for (int x = 0; x < 8; x++)
{
if (aray[indexy+x] == 1)
{
lc4.setLed(0, y, x, true);
}
}
for (int x = 8; x < 16; x++)
{
if (aray[indexy+x] == 1)
{
lc4.setLed(1, y, x-8, true);
}
}
for (int x = 16; x < 24; x++)
{
if (aray[indexy+x] == 1)
{
lc4.setLed(2, y, x-16, true);
}
}
for (int x = 24; x < 32; x++)
{
if (aray[indexy+x] == 1)
{
lc4.setLed(3, y, x-24, true);
}
}
}
}
void SeedArray()
{
randomSeed(analogRead(0));
// for (int i=0; i < 576; i++) {aray[i] = 0;}
for (int a=0; a < 500; a++)
{
int y = random(1, 32);
int x = random(1, 32);
aray[y*32+x] = 1;
}
}
void CheckState()
{
bool flag = true;
for (int i=0; i < 1024; i++)
{
if (aray[i] != newaray[i])
{
flag = false;
}
lastaray[i] = aray[i];
aray[i] = newaray[i];
}
if (flag)
{
SeedArray();
}
else
{
flag = true;
for (int i=0; i < 1024; i++)
{
if (lastaray[i] != newaray[i])
{
flag = false;
}
}
if (flag) {SeedArray();}
}
}