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.

Revision:
2:f4aece10ba62
Parent:
0:d268818ad088
Child:
3:1139b132f983
--- 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();