 public:
   Player *players[2];
   static int active_player;
+  static int interrupt_fired;
 
   Controller() {
     players[0] = new Player(

    }
  };

  void handle_button_interrupt(int button) {
    Button::button_pressed = button;
  };

  void handle_button_press(int button) {
    serprintf("button %d pressed\r\n", button);
    serprintf("before: active_player=%d, button_pressed=%d\r\n", active_player, Button::button_pressed);
    active_player = (Button::button_pressed + 1) % 2;
    players[active_player]->clock->last_update_ms = millis();
    Button::button_pressed = NONE;
    serprintf("after:  active_player=%d, button_pressed=%d\r\n", active_player, Button::button_pressed);
  }

  void tick() {
    if (active_player != NONE) {
      if (players[active_player]->out_of_time()) {
        serprintf("Flag fell for player %d\r\n", active_player);
        active_player = NONE;
        Button::button_pressed = NONE;
        return;
      }

      players[active_player]->tick();
    }

    if ((active_player == NONE || Button::button_pressed == active_player) && Button::button_pressed != NONE)   {
      handle_button_press(Button::button_pressed);
    }     
  }
};
int Controller::active_player = NONE;

Controller controller;



class Button {
public:
  int interrupt_number;
  Button(int interrupt_number_, void (*interrupt_handler)()) {
    interrupt_number = interrupt_number_;
    attachInterrupt(interrupt_number, interrupt_handler, RISING);
  };

  static inline void handle_button_interrupt(int button);
};

void handle_button_interrupt_0() {
  Button::handle_button_interrupt(0);
