lcd keyboard shield - function - feedback

Hello :slight_smile:

I have been tampering a bit with the code for the keyboart for the lcd shield and would like som feedback on it.

Its working as intended, but im still kinda a noob here so some feedback would be appreciated.

int BTN_read(){
//	Function for LCD shield - read buttons
//	REQ: 
//	byte btn_longpress = true;		// longpress ability can be turned off
//	unsigned long btn_timestamp;	// For the timing longpress ability
//	int	btn_old = btn_none;		// For button checking.

	if(btn_longpress){
 		if (millis() >= (btn_timestamp + 1000)) {
   			btn_old = btn_none;
   			btn_timestamp = millis();
   		}
	}
		
	int _btn;
	int adc_key_in = analogRead(0); 
	
	if (adc_key_in > 1000)		{_btn = btn_none;	}
	else if (adc_key_in < 50)	{_btn = btn_right;  }
	else if (adc_key_in < 195)	{_btn = btn_up;		}
	else if (adc_key_in < 350)	{_btn = btn_down;	}
	else if (adc_key_in < 550)	{_btn = btn_left;	}
	else if (adc_key_in < 790)	{_btn = btn_select;	}
		
	if (_btn == btn_old) return btn_none;
	btn_old = _btn;
	btn_timestamp = millis();
	return _btn;
}

Ok, have made it into a library.

you can find it at :

http://www.neve.nu/2013/06/23/key_read-library/