/*
https://www.youtube.com/watch?v=FWSR_7kZuYg
https://en.wikipedia.org/wiki/Conway's_Game_of_Life
- Any live cell with fewer than two live neighbours dies, as if by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
*/
#include <Adafruit_SSD1306.h>
#define WIDTH 128
#define HEIGHT 64
#define RESET 4
#define ADDRESS 0x3C
Adafruit_SSD1306 display(WIDTH, HEIGHT, &Wire, RESET);
#define ARRAY_SIZE WIDTH * HEIGHT
bool oldworld[WIDTH][HEIGHT];
bool newworld[WIDTH][HEIGHT];
unsigned long timer, timeout = 250; // 250ms
void setup()
{
randomSeed(analogRead(0)); // invoke pseudo-randomn rather than static-random (without it)
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, ADDRESS);
display.clearDisplay();
display.display();
}
void loop()
{
if (millis() - timer > timeout) {
makeworld();
}
}
void makeworld()
{
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
byte life = random(2);
display.drawPixel(x, y, life);
newworld[x][y] = life;
}
}
display.display();
}