Pages: [1]   Go Down
Author Topic: Conway's game of "Life"  (Read 3790 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Sr. Member
****
Karma: 1
Posts: 491
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's not terribly interesting on an 8 by 8 grid but I've just implemented Life on the Arduino + an LED matrix. Video on YouTube: , source code on pastebin.com when I get home from work. Towards the end of the video it stumbles into quite a good repeating pattern.

[Update] I've put the code up now at http://arduino.pastebin.com/f22bfe94d.
« Last Edit: February 15, 2008, 03:24:16 pm by Andrew » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 35
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i can hear your arduino saying "i need buttons!"
Logged

UK
Offline Offline
Sr. Member
****
Karma: 1
Posts: 491
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i can hear your arduino saying "i need buttons!"
Do mean for the reset? Yeah, I've got some buttons, just haven't bothered to wire one up.
« Last Edit: February 15, 2008, 03:17:32 pm by Andrew » Logged

Brisbane, Australia
Offline Offline
God Member
*****
Karma: 1
Posts: 593
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And I just got the parts for a 16x16 array.

Hmmm...... smiley-grin
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 507
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

did you hook up an 8x8 led matrix with no ic's or chips??

i cant get my 5x7 to work by itself...
Logged

San Francisco, CA
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Synth Nerd
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Any chance that we could see a schematic of the circuit?
Logged

UK
Offline Offline
Sr. Member
****
Karma: 1
Posts: 491
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, the one thing I haven't done yet is to draw out the circuit. It isn't much of a circuit though as yes, the Arduino pins are wired directly to the 16 pins of the LED matrix. The mapping is defined in the source code I posted here: http://arduino.pastebin.com/f22bfe94d as follows:

Code:
// pin[xx] on led matrix connected to nn on Arduino (-1 is dummy to make array start at pos 1)
int pins[17]= {-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};

which is intended to mean that pin 1 on the matrix is connected to Arduino pin 5, matrix pin 2 is connected to Arduino pin 4 and so on. This makes it easy to update for your own particular wiring. The pinout of the matrix with respect to what pin controls what row and column is also in the source code, and is taken from the datasheet here where I bought the matrix: http://www.rapidonline.com/netalogue/specs/57-0695.pdf

I'll try and draw a diagram tomorrow but I'm not promising anything as I don't really have a decent drawing tool available at home.

Andrew

PS I used some of the analog pins as digital output pins 14, 15 and 16.
Logged

UK
Offline Offline
Sr. Member
****
Karma: 1
Posts: 491
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lovingly crafted diagram now available on ImageShack...



to go with code here: http://arduino.pastebin.com/f22bfe94d

I hope I got the wires in the right places...

[Update] Now also available in a Wiki near you: http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix

Andrew
« Last Edit: February 18, 2008, 08:24:31 am by Andrew » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a draft code of GoLi wich work with a MAX7219. It should work with 8 of them (work in progress). The code may be easily reuse.
Sorry for the roughly code, with french functions name inside :

Code:
#include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

#define Largeur 8
#define Hauteur 8

int analogPin = 0;
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);
    
  
}
Logged

Pages: [1]   Go Up
Jump to: