 	debounce[debounceIdx++] = pressed;
 	debounceIdx &= 3;
 	
-	down = debounce[0] & debounce[1] & debounce[2] & debounce[3];
-	up = debounce[0] | debounce[1] | debounce[2] | debounce[3];
+	keys.down = debounce[0] & debounce[1] & debounce[2] & debounce[3];
+	keys.up = debounce[0] | debounce[1] | debounce[2] | debounce[3];
 	
 	// Determine which buttons have freshly been pressed and return the result
-	prevButtons = buttons;
-	buttons &= up;
-	buttons |= down;
-	return buttons & (buttons ^ prevButtons);
+	uint8_t prevStates = states;
+	states &= keys.up;
+	states |= keys.down;
+	keys.justPressed = states & (states ^ prevStates);
+	
+	if(states != 0) {
+		if(states != prevStates) {
+			timeInStates = millis();
+		} else {
+			if(millis() - timeInStates > LONG_PRESS_MILLIS) {
+				keys.longPressed = keys.up;
+			}
+		}
+	} else {
+		keys.longPressed = 0;
+	}
+	
+	return &keys;
 }
 
-/*void twiceASecond() {
-	g_time2Hz++;
-	g_time1Hz = g_time2Hz >> 1;
-	g_timeMinutes = g_time1Hz % 60;
-}*/
 

}

// 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;



#include <avr/pgmspace.h>
#include <Time.h>
#include "english_v2.h"

#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 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
