Fork without short circuits

Dependents:   SaveKeypad

Fork of keypad by HM Yoong

No extra hardware is needed besides the wires and switches. The columns are outputs configured with open drain. The rows are inputs configured with pull up resistors. A key press pulls down its row. With scanning the column is determined thereafter.

See SaveKeypad for an example usage.

Files at this revision

API Documentation at this revision

Comitter:
gj_schoneveld
Date:
Thu Nov 08 19:04:08 2012 +0000
Parent:
15:873a9a452ef1
Commit message:
Updated Debounce

Changed in this revision

keypad.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 873a9a452ef1 -r a9feaa7ac039 keypad.cpp
--- a/keypad.cpp	Sun Nov 04 09:56:24 2012 +0000
+++ b/keypad.cpp	Thu Nov 08 19:04:08 2012 +0000
@@ -44,16 +44,9 @@
 int Keypad::DebouncedScan()
 {
     /* debounce */
-    int key1 = Scan();
-    
     wait_ms(_debounce);
-    
-    int key2 = Scan();
-    
-    if (key1 != key2)
-        return -1;
-    else
-        return key1;
+
+    return Scan();
 }
 
 int Keypad::Scan()
@@ -69,7 +62,7 @@
     if (!(0 <= r && r < row_count))
         return -1;
 
-    /* scan columns to find out which one pulls down the row */ 
+    /* scan columns to find out which one pulls down the row */
     int c = -1;
     for (c = 0; c < col_count; c++) {
         _cols = ~(1 << c);
@@ -86,21 +79,18 @@
 
     return r * col_count + c;
 }
+
 int Keypad::DebouncedScanMultiple()
 {
     /* debounce */
-    int key1 = ScanMultiple();
-    
     wait_ms(_debounce);
-    
-    int key2 = ScanMultiple();
-    
-    return key1 & key2;
+
+    return ScanMultiple();
 }
 
 int Keypad::ScanMultiple()
 {
-    int res = 0;    
+    int res = 0;
     for (int c = 0; c < col_count; c++) {
         _cols = ~(1 << c);
         for (int r = 0; r < row_count; r++) {
@@ -109,7 +99,7 @@
             }
         }
     }
-    
+
     return res;
 }
 
@@ -117,7 +107,7 @@
 {
     /* lookup */
     int position = DebouncedScan();
-    
+
     /* call back a valid position */
     if (position >= 0)
         _input.call(position);