 int cmode = 0;
 
 int incomingByte = 0;
-unsigned long heartbeat, track_last_heartbeat, track_missing_heartbeat, track_uart;
-int show_missing_beat = 1;
+int receivedHeartbeat = 0;
+unsigned long heartbeat, last_heartbeat;
+unsigned long track_last_heartbeat, track_missing_heartbeat, track_uart;
+
 
 void setup() {
   pinMode(PUSHLOCK_NO, INPUT_PULLUP);
   pinMode(PUSHLOCK_NC, INPUT_PULLUP);
   pinMode(BUTTON, INPUT_PULLUP);
+  pinMode(SYSTEM_ON, INPUT_PULLUP);
 
   pinMode(LED_R, OUTPUT);
   pinMode(LED_G, OUTPUT);
   pinMode(LED_B, OUTPUT);
-  pinMode(RUN, OUTPUT);
-
-  attachInterrupt(digitalPinToInterrupt(BUTTON), isr_button_push, FALLING);
-  attachInterrupt(digitalPinToInterrupt(PUSHLOCK_NO), isr_pushlock_change, CHANGE);
-  //attachInterrupt(digitalPinToInterrupt(PUSHLOCK_NC), pushlock_open, CHANGE);
-
-  pushlock = digitalRead(PUSHLOCK_NO);
+  pinMode(SYSTEM_RUN, OUTPUT);
+
+  pushlock = digitalRead(PUSHLOCK);
 
   track_last_heartbeat = millis();
   track_missing_heartbeat = track_last_heartbeat;


void loop() {
  heartbeat = detect_heartbeat();
  led_heartbeat_ack();
  statefunc = (StateFunc)(*statefunc)();    //FSM
}

//isr
void isr_button_push() {
  button = 1;
}

void isr_pushlock_change() {
  pushlock = digitalRead(PUSHLOCK_NO);
}

//physical routines
void serial_flush() {
  int buf;
  while (Serial.available() > 0) {
      buf = Serial.read();
  }
}

void touch_run_pin() {
  digitalWrite(RUN, HIGH);

long detect_heartbeat_abort();
long get_last_heartbeat();

//heartbeat signals
void signal_heartbeat();
void signal_heartbeat_missing();
void signal_heartbeat_ack();
void signal_heartbeat_abort();
void signal_heartbeat_system_shutdown();

//generic led routines
void led_color(byte red, byte green, byte blue);
void led_off(byte value);
void led_white(byte value);
void led_red(byte value);
void led_green(byte value);
void led_blue(byte value);

//led signals
void signal_server_locked();
//void siganimate_

//uart routines
void serial_flush();
void debug_print(char *msg);
//uart messages
void send_ok();
void send_shutdown();
void send_abort_shutdown();

//States                          //state matching led animations
void *server_bootable();          void animate_bootable();
