Conway's game of life applied to the mbed and an RA8875 LCD.

Dependencies:   LifeRules mbed RA8875

Inspired by a forum discussion on the mbed site, this version was scaled to support up to a 480x272 display - in a monochrome mode, or at a lower resolution in color (the color shows simple animation for birthing and dying cells).

Leveraging the LifeRules class, the game can be easily adapted to other displays - whether monochrome or color.

By default, this version allocates memory from the Ethernet ram banks, so avoids the memory limitations of some designs.

It should be simple to adapt it to any display - color or b&w, high or low resolution.

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Wed Apr 23 22:57:50 2014 +0000
Parent:
1:f3f2d31f0226
Child:
3:1139b132f983
Commit message:
Cleaned up the code, permit either monochrome or color display, and compile time defined resolution for the display.

Changed in this revision

LifeRules.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/LifeRules.lib	Wed Apr 16 22:28:16 2014 +0000
+++ b/LifeRules.lib	Wed Apr 23 22:57:50 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/WiredHome/code/LifeRules/#d43dc92ae767
+http://mbed.org/users/WiredHome/code/LifeRules/#860ae49fedb7
--- a/main.cpp	Wed Apr 16 22:28:16 2014 +0000
+++ b/main.cpp	Wed Apr 23 22:57:50 2014 +0000
@@ -1,10 +1,14 @@
+// game of life implementation inspired by this forum thread
+// http://mbed.org/forum/helloworld/topic/4822/
+// 
 #include "mbed.h"
 #include "RA8875.h"
 #include "LifeRules.h"
 
 // Define the life-map size
-#define LIFE_W 480
-#define LIFE_H 272
+#define LIFE_W 300
+#define LIFE_H 200
+#define LIFE_C Life::color
 
 // Define the screen size
 #define SCREEN_W 480
@@ -27,9 +31,11 @@
 #endif
 
 
-Life life(LIFE_W, LIFE_H, Life::monochrome);
+Life life(LIFE_W, LIFE_H, LIFE_C);
 
-RA8875 lcd(p5, p6, p7, p12, NC, "tft");
+// NOT USING p21, but the mbed lib v82 does not work if NC is part
+// of a constructor. See thread http://mbed.org/forum/bugs-suggestions/topic/4859/
+RA8875 lcd(p5, p6, p7, p12, p21, "tft");
 
 // Where on screen do we locate it?
 #define LIFE_OFFSET_X (SCREEN_W - LIFE_W)
@@ -55,16 +61,13 @@
 void gentest();
 void genBlinker();
 
-void ScreenUpdate()   //print the results from the new array
+void ScreenUpdate()
 {
     lcd.window(LIFE_OFFSET_X, LIFE_OFFSET_Y, LIFE_W, LIFE_H);
     lcd._StartGraphicsStream();
-    //pc.printf("ScreenUpdate\r\n");
     for (int j = 0; j < LIFE_H; j++) {
         for (int i = 0; i < LIFE_W; i++) {
             Life::ValueOfLife lifeState = life.getbit(i,j);
-            //Life::ValueOfLife nextState = life.getbit(i,j,1);
-            //pc.printf("%d%d ", lifeState, nextState);
             switch (lifeState) {
                 case Life::dead:
                     lcd._putp(Black);
@@ -84,9 +87,7 @@
                     break;
             }
         }
-        //pc.printf("\r\n");
     }
-    //pc.printf("\r\n");
     lcd._EndGraphicsStream();
     lcd.WindowMax();
 }
@@ -153,7 +154,7 @@
              );
 
     ScreenUpdate();
-    wait(1); //See the initial configuration
+    wait(1);
     
     while(1) {
         CheckForUserInteraction();
--- a/mbed.bld	Wed Apr 16 22:28:16 2014 +0000
+++ b/mbed.bld	Wed Apr 23 22:57:50 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file