Hi
I wondering if some could guide to
add a push botton to this game of life code
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,1);
#define Largeur 8
#define Hauteur 8
unsigned long delaytime=150;
int idx=0;
int t1[8][8] = {{0, 0, 0, 1, 0, 0, 0, 0},
{0, 0, 1, 0, 1, 0, 0, 0},
{0, 1, 0, 1, 1, 0, 0, 0},
{1, 0, 1, 0, 0, 1, 1, 0},
{0, 1, 1, 0, 0, 1, 0, 1},
{0, 0, 0, 1, 1, 0, 1, 0},
{0, 0, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0}};
int t2[8][8];
/*******************************************************************************/
/* set all the box to zero*/
void mise_a_0(int t1[8][8],int t2[8][8])
{
int i,j;
for(i=0;i<Largeur;i++)
{
for(j=0;j<Hauteur;j++)
{
t1[i][j]=0;
t2[i][j]=0;
}
}
}
/*******************************************************************************/
/* clear window */
void clear_fenetre()
{
lc.clearDisplay(0);
}
/*******************************************************************************/
/* display cells */
void affiche(int t1[8][8])
{
int i,j;
//lc.clearDisplay(0);
//_setcursortype(_NOCURSOR);
//textcolor(14);
for(i=0;i<Largeur;i++)
{
for(j=0;j<Hauteur;j++)
{
lc.setLed(0,i,j,t1[i][j]);
}
}
}
/*******************************************************************************/
/* compute previous generation*/
void affect_etat_precedent(int t1[8][8],int t2[8][8])
{
int i,j;
for(i=0;i<Largeur;i++)
{
for(j=0;j<Hauteur;j++)
{
t2[i][j]=t1[i][j];
}
}
}
/*******************************************************************************/
/* compute next generation */
void affect_etat_suivant(int t1[8][8],int t2[8][8])
{
int i,j;
for(i=0;i<Largeur;i++)
{
for(j=0;j<Hauteur;j++)
{
t1[i][j]=t2[i][j];
}
}
}
/*******************************************************************************/
/* compute neighborough cells */
#
void calcul_cellule(int t1[8][8],int t2[8][8])
{
int i,j,a;
for(i=0;i<Largeur;i++)
{
for(j=0;j<Hauteur;j++)
{
if((i==0)&&(j==0))
{
a=t1[i][j+1]+t1[i+1][j]+t1[i+1][j+1]+t1[i][69]+t1[i+1][69]+t1[19][j]+t1[19][j+1]+t1[19][69];
}
if((i!=0)&&(j!=0)&&(i!=(Largeur-1))&&(j!=(Hauteur-1)))
{
a=t1[i-1][j-1]+t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i+1][j+1]+t1[i+1][j]+t1[i+1][j-1]+t1[i][j-1];
}
if((i==0)&&(j!=0)&&(j!=(Hauteur-1)))
{
a=t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i+1][j+1]+t1[i][j+1]+t1[19][j-1]+t1[19][j]+t1[19][j+1];
}
if((i==0)&&(j==(Hauteur-1)))
{
a=t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i][0]+t1[i+1][0]+t1[19][0]+t1[19][j]+t1[19][j-1];
}
if((i==(Largeur-1))&&(j==0))
{
a=t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i][69]+t1[i-1][69]+t1[0][j]+t1[0][j+1]+t1[0][69];
}
if((i==(Largeur-1))&&(j!=0)&&(j!=(Hauteur-1)))
{
a=t1[i][j-1]+t1[i][j+1]+t1[i-1][j-1]+t1[i-1][j]+t1[i-1][j+1]+t1[0][j]+t1[0][j-1]+t1[0][j+1];
}
if((i==(Largeur-1))&&(j==(Hauteur-1)))
{
a=t1[i][j-1]+t1[i-1][j-1]+t1[i-1][j]+t1[0][j]+t1[0][j-1]+t1[i][0]+t1[i-1][0]+t1[0][0];
}
if((i!=0)&&(i!=(Largeur-1))&&(j==0))
{
a=t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i+1][j+1]+t1[i+1][j]+t1[i][69]+t1[i-1][69]+t1[i+1][69];
}
if((i!=0)&&(i!=(Largeur-1))&&(j==(Hauteur-1)))
{
a=t1[i-1][j]+t1[i-1][j-1]+t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i][0]+t1[i-1][0]+t1[i+1][0];
}
if((t1[i][j]==0)&&(a==3)){t2[i][j]=1;}
if((t1[i][j]==1)&&((a==2)||(a==3))){t2[i][j]=1;}
if((t1[i][j]==1)&&((a==1)||(a==0)||(a>3))){t2[i][j]=0;}
}
}
}
/*******************************************************************************/
/* randomize */
void alea(int t1[8][8])
{
int i,j;
randomSeed(millis());
for(i=0;i<Largeur;i++)
{
for(j=0;j<Hauteur;j++)
{
t1[i][j]=random(2);
}
}
}
/*******************************************************************************/
/*permutation*/
void permut(int *a,int *b)
{
int aux;
aux=*a;
*a=*b;
*b=aux;
}
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,15);
lc.clearDisplay(0);
// alea(t1);
}
void loop()
{
if (idx++ > 30)
{
alea(t1);
lc.clearDisplay(0);
delay(300);
idx=0;
}
affect_etat_precedent(t1,t2);
calcul_cellule(t1,t2);
affect_etat_suivant(t1,t2);
affiche(t1);
delay(delaytime);
}
original code from
http://forum.arduino.cc//index.php?PHPSESSID=hn7s31bm96cosm8uj44jeu81v0&topic=92787.0