5 way switch shield code problem
hi,
i have lcd4884 shield , try perform button press activate action once when button pressed.
i use libary called analogkeypad has debounce build in.
http://www.oryshed.com/arduino/lcd-48x84-shield
although switch function works perfect , gives single printfunction in monitor when select key pressed , kept pressed.
however own function activated switch key press needs perform single step keeps running.
i need function step thorugh menu stucture , other button functions perform other steps.
must simple overlook basic.
paco
i have lcd4884 shield , try perform button press activate action once when button pressed.
i use libary called analogkeypad has debounce build in.
http://www.oryshed.com/arduino/lcd-48x84-shield
although switch function works perfect , gives single printfunction in monitor when select key pressed , kept pressed.
however own function activated switch key press needs perform single step keeps running.
i need function step thorugh menu stucture , other button functions perform other steps.
must simple overlook basic.
code: [select]
#include "analogkeypad.h"
/*************************************************
* send pressed key serial monitor *
**************************************************/
void printkey(int8_t keycode);
boolean btnselect;
void setup()
{
serial.begin(9600);
serial.println(f("analog keypad v1.0"));
serial.println(f("press key..."));
}
analogkeypad keypad(a0);
void loop()
{
int8_t keycode;
// simple way read keys
// keyupevent must called regularly main loop
// takes care of reading analog input , debouncing
if ( (keycode = keypad.keyupevent()) != analogkeypad::no_key)
{ serial.print("event key up: ");
printkey(keycode);
}
// alternative way of reading keys if need more fine grained control
// if (keypad.run()) // must called regularly main loop
// { if (keypad.waspressed())
// serial.print(f("pressed: "));
// else if (keypad.wasreleased())
// serial.print(f("released: "));
//
// printkey(keypad.getcurrentkey());
// }
if (btnselect == 1)
{
serial.println (" print once per button press ");
}
}
void printkey(int8_t keycode)
{ string keyname;
switch (keycode)
{ case 'u':
keyname = "up";
break;
case 'd':
keyname = "down";
break;
case 'l':
keyname = "left";
break;
case 'r':
keyname = "right";
break;
case 's':
keyname = "===============================================select";
btnselect = 1;
break;
}
serial.println(keyname);
}
paco
in case wondering, me...
code: [select]
/**********************************************************************************
must called regularly main loop register key events.
returns key code of released key or no_key if no key released
**********************************************************************************/
int8_t analogkeypad::keyupevent()
{
if (run() && wasreleased())
return getcurrentkey();
else
return analogkeypad::no_key;
}
Arduino Forum > Using Arduino > Programming Questions > 5 way switch shield code problem
arduino
Comments
Post a Comment