Here is a slice of conways life using a 4x20 lcd with each character cell split into three cells vertically using special characters so that it is a 12x20 life grid. Equipment is just a usb duino hotglued back to back with the LCD (with a layer of thin cardboard in-between), using a 4 wire interface. Sorry, I must be bored ![]()
Code fragment:
#define rows 12
#define columns 20
byte display [] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
byte tmp [] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void loop (void){
lcd.init();
byte running=1;
while(running==1){
running=0;
//update neighbor counts
for(int y = 0; y < rows; y++){
for(int x = 0; x < columns; x++)
tmp[y*columns+x]=getNeighborCount(display,x,y);
}
//display the array
for(int y = 0; y < rows; y+=3){
lcd.gotoXY(0,y/3);
for(int x = 0; x < columns; x++){
byte n1=display[y*columns+x];
byte n2=getNeighbor(display,x,y,4)*2;
byte n3=getNeighbor(display,x,y+1,4)*4;
lcd.LcdDataWrite(n1|n2|n3);
}
}
//see who lives and who dies
for(int y = 0; y < rows; y++){
for(int x = 0; x < columns; x++){
byte b = display[y*columns+x];
byte n = tmp[y*columns+x];
if(b==0){
if(n==3) {
display[y*columns+x] = 1; //birth
running=1;
}
}else{
if(n==2 || n==3)
display[y*columns+x] = 1; //survival
else {
display[y*columns+x] = 0; //death
running = 1;
}
}
}
}
}
lcd.gotoXY(0,0);
lcd.print("DONE");
while(true);
}
byte getNeighborCount(byte a[], byte x, byte y){
byte c = 0;
for(byte d = 0;d < 8; d++)
if(getNeighbor(a,x,y,d) != 0)
c++;
return c;
}
byte getNeighbor(byte a[], byte x, byte y, byte dir){
byte nx=x;
byte ny=y;
if(dir == 7 || dir == 0 || dir == 1)
ny--;
if(dir == 3 || dir == 4 || dir == 5)
ny++;
if(dir == 5 || dir == 6 || dir == 7)
nx--;
if(dir == 1 || dir == 2 || dir == 3)
nx++;
if(nx==255) nx = columns - 1;
if(nx==columns) nx = 0;
if(ny==255) ny = rows - 1;
if(ny==rows) ny = 0;
return a[ny*columns+nx];
}
...
//creating the custom fonts:
LcdCommandWrite(B01000000); // set cgram
static byte chars[] PROGMEM ={
B00000,B11111,B00000,B11111,B00000,B11111,B00000,B11111,
B00000,B11111,B00000,B11111,B00000,B11111,B00000,B11111,
B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00000,
B00000,B00000,B11111,B11111,B00000,B00000,B11111,B11111,
B00000,B00000,B11111,B11111,B00000,B00000,B11111,B11111,
B00000,B00000,B00000,B00000,B00000,B00000,B00000,B00000,
B00000,B00000,B00000,B00000,B11111,B11111,B11111,B11111,
B00000,B00000,B00000,B00000,B11111,B11111,B11111,B11111};
for(byte x=0;x<8;x++)
for(byte y=0;y<8;y++)
LcdDataWrite(pgm_read_byte(&chars[y*8+x])); //write the character data to the cgram