PHP Code:
void loop()
{
if(bcount++ > BCT) check_battery();
delay(300); // a small delay //
int keyinput = getkeypress();
if(keyinput)
{
do_menu(keyinput);
}
}
int getkeypress()
{
/*
No need to check individual keys, we simply check them all at once...
We could allow key combinations if so desired...
*/
int keydata = PINB;
// Loose the bit we don't want, we just need PB2 to PB5 //
keydata = ((keydata << 2)>> 4);
// debounce //
delay(5);
if(keydata == ((PINB<<2)>>4) && keydata < 15)
{
return(keydata);
}
return(0);
}
void do_menu(int input)
{
lcd.clear();
lcd.setCursor(0, 0);
// examples //
switch(input)
{
case 7: lcd.print(" Frequency ");
break;
case 11: lcd.print(" Pulses ");
break;
case 13: lcd.print(" something else ");
break;
case 14: lcd.print(" <----------> ");
break;
default: // do something...
break;
}
}

Mike


Leave a comment: