Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 14:2073b80c69cd, committed 2016-11-04
- Comitter:
- ryood
- Date:
- Fri Nov 04 16:09:03 2016 +0000
- Parent:
- 13:75af5ebeecea
- Commit message:
- keypad 4x4: Debounce
Changed in this revision
| ExioMcp23s17Keypad4x4.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ExioMcp23s17Keypad4x4.h Fri Nov 04 15:17:32 2016 +0000
+++ b/ExioMcp23s17Keypad4x4.h Fri Nov 04 16:09:03 2016 +0000
@@ -18,7 +18,9 @@
public:
ExioMcp23s17Keypad4x4(ExioMcp23s17* _pDevice, ExioPort _port) :
pDevice(_pDevice),
- port(_port)
+ port(_port),
+ keyVal(-1),
+ keyBuffer(-1)
{
pDevice->ioDirection(port, IO_DIRECTION);
pDevice->ioPullup(port, IO_PULLUP);
@@ -33,30 +35,6 @@
void setSampleFrequency(int i) { ticker.attach_us(this, &ExioMcp23s17Keypad4x4::callback, i); }
int read() { return keyVal; }
-
- /*
- //------------------------------------------------------
- // keyScan(): 押して離されたキー
- // return: キースキャンの結果 0..15
- // 変化がない場合は -1
- //------------------------------------------------------
- int keyScan()
- {
- int kv, kvv;
- // チャタリング防止
- kv = keyScan1();
- Thread::wait(10);
- kvv = keyScan1();
-
- if (kv == kvv) {
- if (kv != keyBuff) {
- keyBuff = kv;
- return kv;
- }
- }
- return -1;
- }
- */
private:
//------------------------------------------------------
@@ -64,7 +42,6 @@
// return: キースキャンの結果 0..15
// 押されていない場合は -1
//------------------------------------------------------
-
int keyScan1()
{
uint8_t data;
@@ -89,13 +66,19 @@
// The Ticker callback function
void callback()
{
- keyVal = keyScan1();
+ //チャタリング防止
+ int v = keyScan1();
+ if (v == keyBuffer) {
+ keyVal = v;
+ }
+ keyBuffer = v;
}
Ticker ticker;
ExioMcp23s17* pDevice;
ExioPort port;
int keyVal;
+ int keyBuffer;
};
#endif //_MCP23S17Keypad4x4_