Skip to content

Commit

Permalink
allow switching between programs
Browse files Browse the repository at this point in the history
  • Loading branch information
wertarbyte committed Apr 2, 2011
1 parent 7989d2c commit 3cd7842
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
25 changes: 20 additions & 5 deletions 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
Expand Down Expand Up @@ -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
Expand All @@ -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 );
}
}
15 changes: 15 additions & 0 deletions 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 },
};

0 comments on commit 3cd7842

Please sign in to comment.