diff --git a/Arduino-Breakout.pde b/Arduino-Breakout.pde index e34aac0..0c62203 100644 --- a/Arduino-Breakout.pde +++ b/Arduino-Breakout.pde @@ -1,5 +1,10 @@ /* - Implement a breakout style game on a 5x7 LED matrix + Implement a several games and programs + on a 5x7 LED matrix + + Currently implemented subprograms: + * Breakout + * Conway's game of life The 5 rows of the LED matrix are connected directly to arduino pins, while the 7 columns are controlled @@ -32,14 +37,21 @@ Arduino A0 -> Poti 10 kOhm Arduino 7 -> push button + Arduino 1 -> push button */ // functions for handling the display #include "display.h" #include "input.h" -#include "breakout.h" +#include "programs.h" + +static int current_program = 0; +void load_program(int i) { + programs[i].init(); + current_program = i; +} void setup() { // used for seeding the RNG @@ -49,11 +61,14 @@ void setup() { setup_display(); setup_input(); - // the actual game code - breakout_setup(); + load_program(0); } void loop() { - breakout_loop(); update_display(); + programs[current_program].loop(); + + if (btn_pressed(1)) { + load_program( (current_program+1)%PROGRAM_CNT ); + } } diff --git a/programs.h b/programs.h new file mode 100644 index 0000000..5f25626 --- /dev/null +++ b/programs.h @@ -0,0 +1,15 @@ +#include "breakout.h" +#include "conway.h" + +struct program { + void (*init)(void); + void (*loop)(void); +}; + +#define PROGRAM_CNT 2 +program programs[PROGRAM_CNT] = { + /* Breakout */ + { &breakout_setup, &breakout_loop }, + /* Conway's Game of Life */ + { &conway_setup, &conway_loop }, +};