/********************************************* * Author: Leah Buechley * Filename: game_of_life.c * Chip: ATMEGA16 * Date: 10/1/2005 * Purpose: * This program implements the Game of Life on a 6 x 14 LED * array. It was written for a wearable LED tank top. * More information at: * http://www.cs.colorado.edu/~buechley/diy/diy_tank.html * Copyright information: http://www.gnu.org/copyleft/gpl.html Copyright (C) 2005 Leah Buechley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *********************************************/ #include #include "game_of_life.h" /* constants and variables defining the size and properties of the LED array and corresponding Game of Life (GOL) array. the GOL array will hold information about the current and next state for each cell in the GOL array/grid. */ const unsigned char number_rows = 6; const unsigned char number_columns = 14; const unsigned char size_of_array = 84; unsigned char array [6][14]; /* constants for resetting the values of the GOL array */ const unsigned char on_next_on = 3; //current state is on and next state is on const unsigned char off_next_on = 2; //current state is off and next state is on const unsigned char on_next_off = 1; //current state is on and next state is off (default on state) const unsigned char off_next_off = 0; //current state is off and next state is off (default off state) /******************************************************************************************/ /* initialization function */ /******************************************************************************************/ //initializes the pins to be used for the display as outputs void initialize_tank_pins_as_output (void) { row0_output; row1_output; row2_output; row3_output; row4_output; row5_output; col0_output; col1_output; col2_output; col3_output; col4_output; col5_output; col6_output; col7_output; col8_output; col9_output; col10_output; col11_output; col12_output; col13_output; } /******************************************************************************************/ /* functions for row-column display */ /******************************************************************************************/ /* given a row value (i), and a column value (j), turns on the LED at position i,j in the LED array for a time specified by the delay loop */ void row_column_display (unsigned char i, unsigned char j) { unsigned char delay; if (i==0) row0_low; else if (i==1) row1_low; else if (i==2) row2_low; else if (i==3) row3_low; else if (i==4) row4_low; else if (i==5) row5_low; if (j==0) col0_high; else if (j==1) col1_high; else if (j==2) col2_high; else if (j==3) col3_high; else if (j==4) col4_high; else if (j==5) col5_high; else if (j==6) col6_high; else if (j==7) col7_high; else if (j==8) col8_high; else if (j==9) col9_high; else if (j==10) col10_high; else if (j==11) col11_high; else if (j==12) col12_high; else if (j==13) col13_high; for (delay=0;delay<5;delay++); all_off (); } /* given a column value (j), turns on the LEDs in column j in the LED array for a time specified by the delay loop */ void column_display (unsigned char j) { unsigned char delay; row0_low; row1_low; row2_low; row3_low; row4_low; row5_low; if (j==0) col0_high; else if (j==1) col1_high; else if (j==2) col2_high; else if (j==3) col3_high; else if (j==4) col4_high; else if (j==5) col5_high; else if (j==6) col6_high; else if (j==7) col7_high; else if (j==8) col8_high; else if (j==9) col9_high; else if (j==10) col10_high; else if (j==11) col11_high; else if (j==12) col12_high; else if (j==13) col13_high; for (delay=0;delay<10;delay++); all_off (); } /******************************************************************************************/ /* functions useful for troubleshooting display */ /******************************************************************************************/ /* turns on all the LEDs in the array */ void all_on (void) { //rows low row0_low; row1_low; row2_low; row3_low; row4_low; row5_low; //columns high col0_high; col1_high; col2_high; col3_high; col4_high; col5_high; col6_high; col7_high; col8_high; col9_high; col10_high; col11_high; col12_high; col13_high; } /* turns off all the LEDs in the array */ void all_off (void) { //rows high row0_high; row1_high; row2_high; row3_high; row4_high; row5_high; //columns low col0_low; col1_low; col2_low; col3_low; col4_low; col5_low; col6_low; col7_low; col8_low; col9_low; col10_low; col11_low; col12_low; col13_low; } /* loops through all of the LEDs in the array turning each one on in turn */ void loop_lights (void) { unsigned char x,y; int z; for(x=0;x