Basically this code is for a modified game, of life battle mode that is flashed on and automatically runs when powered on. Currently working on a custom shell for the enclosure so it looks somewhat usable
Soory for low quality picture my camera isn't good . Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define WIDTH 128
#define HEIGHT 64
#define SCALE 2 // 64x32 grid
Adafruit_SSD1306 display(WIDTH, HEIGHT, &Wire, -1);
bool world[64][32];
bool nextWorld[64][32];
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
randomSeed(analogRead(A0));
seedWar();
}
void seedWar() {
for(int x=0;x<64;x++) for(int y=0;y<32;y++)
world[x][y] = random(0,100) > 72; // random war start
}
void loop() {
int alive = 0;
// draw
display.clearDisplay();
for(int x=0;x<64;x++) for(int y=0;y<32;y++) {
if(world[x][y]) {
display.fillRect(x*SCALE, y*SCALE, SCALE, SCALE, WHITE);
alive++;
}
}
display.display();
// THE FLASH - remembrance
if(alive > 0 && alive < 4) {
delay(200);
display.invertDisplay(true); delay(150);
display.invertDisplay(false);
}
// auto-reseed if too empty - keeps powerbank awake
if(alive < 12) { seedWar(); delay(300); return; }
// conway logic
for(int x=0;x<64;x++) for(int y=0;y<32;y++) {
int n = count(x,y);
if(world[x][y]) nextWorld[x][y] = (n==2 || n==3);
else nextWorld[x][y] = (n==3);
}
memcpy(world, nextWorld, sizeof(world));
delay(120);
}
int count(int x,int y){
int c=0;
for(int i=-1;i<=1;i++) for(int j=-1;j<=1;j++){
if(i==0&&j==0) continue;
int nx=(x+i+64)%64, ny=(y+j+32)%32;
if(world[nx][ny]) c++;
}
return c;
}