+
 
 #include <avr/pgmspace.h>
-//#include <TimerOne.h>
 #include <Time.h>
 #include "english_v2.h"
 
-#define TiMPIN			A0
-#define BUTTON_L		A1
-#define BUTTON_R		A2
+#define TiMPIN				A0
+#define BUTTON_L			8
+#define BUTTON_R			12
+#define PIN_LOW				10
 
-#define BUTTON_L_IDX	1
-#define BUTTON_R_IDX	2
+#define BUTTON_L_IDX		1
+#define BUTTON_R_IDX		2
 
-/*// Stores the current time, in half-seconds, since the beginning of the day.
-uint16_t g_time2Hz = 0;
-uint16_t g_time1Hz = 0;
-uint16_t g_timeMinutes = 0;*/
+#define LONG_PRESS_MILLIS	2000
+
+typedef struct KeyStates{
+	uint8_t justPressed;	// Buttons that have just been pressed
+	uint8_t longPressed;	// Buttons that have been pressed for a long time
+	uint8_t up;				// Buttons that are pressed
+	uint8_t down;			// Buttons that are released
+};
 
 void setup() {
 	// Setup the GPIO

}

// Returns a byte with the idx of any newly pressed keys set to '1'. Also includes debouncing.
uint8_t getKeys() {
	static uint8_t debounce[4];			// Stores the queue of the push button states
	static uint8_t debounceIdx = 0;		// Stores the index we are current at within the debounce queue
	static uint8_t buttons;				// Stores the state of the buttons
	
	uint8_t prevButtons;				// Temp variable used for comparison with previous button states
	uint8_t pressed = 0;				// Holds which buttons are currently pressed
	uint8_t up;							// Indicates which buttons have been pressed for a long time
	uint8_t down;						// Indicates which buttons have been released for a long time
	
	if(digitalRead(BUTTON_L) == LOW) {
		pressed |= BUTTON_L_IDX;

	pinMode(BUTTON_R, INPUT);
	digitalWrite(BUTTON_R, HIGH);
	
	pinMode(PIN_LOW, OUTPUT);
	digitalWrite(PIN_LOW, LOW);
	
	// Start the serial port
	Serial.begin(9600);
	
	// Initialise the display
	disp_init();
}

void loop() {
	static int prev_sec = second();
	static int prev_min = minute();
	int sec;
	int min;
	
	uint16_t ledStates[8] = { 0 };
	KeyStates *keys = NULL;
		
	keys = getKeys();
	
	// Depending on the keys just pressed, take the necessary action
	switch(keys->longPressed) {
	case BUTTON_L_IDX:
		Serial.println("Pressed left a long time");
		break;
	case BUTTON_R_IDX:
		Serial.println("Pressed right a long time");
		break;
	case BUTTON_L_IDX | BUTTON_R_IDX:
		Serial.println("Pressed left and right a long time");
		break;
	default:
		break;
	}
	
	sec = second();
	min = minute();
	if(prev_sec != sec) {
		if(prev_min != min) {
			int totalMinutes = (hour() * 60) + min;
			displayWord(ledStates, totalMinutes / 5);
			prev_min = min;
		}

		// Make the bottom right LED blink every second
		ledStates[7] |= sec & 0x01;
		prev_sec = sec;

		disp_display(ledStates);
	}
}

void displayWord(uint16_t *ledStates, int time) {
	// Loop through every line
//	Serial.print("Time: ");
//	Serial.println(time);

	for(int dispIdx = 0; dispIdx < 4; dispIdx++) {

