3x4 keypad library (Extended not only 3x4 but 4x4,4x5 and 5x5 keys)

Dependents:   Keypad_input_OS2 Keypad_input

see /users/kenjiArai/notebook/keypadkey-matrix--control/

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Mon Apr 13 02:04:25 2020 +0000
Parent:
3:0ea41738b560
Child:
5:8929ce2f393c
Commit message:
modified DigitalOut to DigitalInOut

Changed in this revision

Keypad.cpp Show annotated file Show diff for this revision Revisions of this file
Keypad.h Show annotated file Show diff for this revision Revisions of this file
--- a/Keypad.cpp	Mon Apr 06 04:53:25 2020 +0000
+++ b/Keypad.cpp	Mon Apr 13 02:04:25 2020 +0000
@@ -8,7 +8,7 @@
  *  http://www7b.biglobe.ne.jp/~kenjia/
  *  https://os.mbed.com/users/kenjiArai/
  *      Created:    September 27th, 2017
- *      Revised:    April      6th, 2020
+ *      Revised:    April     13th, 2020
  */
 
 #include "Keypad.h"
@@ -33,9 +33,9 @@
     k_in[1]  = new DigitalIn(kb, PullUp);
     k_in[2]  = new DigitalIn(kc, PullUp);
     k_in[3]  = new DigitalIn(kd, PullUp);
-    k_out[0] = new DigitalOut(kx);
-    k_out[1] = new DigitalOut(ky);
-    k_out[2] = new DigitalOut(kz);
+    k_out[0] = new DigitalInOut(kx, PIN_OUTPUT, OpenDrain, 1);
+    k_out[1] = new DigitalInOut(ky, PIN_OUTPUT, OpenDrain, 1);
+    k_out[2] = new DigitalInOut(kz, PIN_OUTPUT, OpenDrain, 1);
     key_mode    = 12;
     key_in_num  = 4;
     key_out_num = 3;
@@ -51,10 +51,10 @@
     k_in[1]  = new DigitalIn(kb, PullUp);
     k_in[2]  = new DigitalIn(kc, PullUp);
     k_in[3]  = new DigitalIn(kd, PullUp);
-    k_out[0] = new DigitalOut(kx);
-    k_out[1] = new DigitalOut(ky);
-    k_out[2] = new DigitalOut(kz);
-    k_out[3] = new DigitalOut(kw);
+    k_out[0] = new DigitalInOut(kx, PIN_OUTPUT, OpenDrain, 1);
+    k_out[1] = new DigitalInOut(ky, PIN_OUTPUT, OpenDrain, 1);
+    k_out[2] = new DigitalInOut(kz, PIN_OUTPUT, OpenDrain, 1);
+    k_out[3] = new DigitalInOut(kw, PIN_OUTPUT, OpenDrain, 1);
     key_mode    = 16;
     key_in_num  = 4;
     key_out_num = 4;
@@ -71,10 +71,10 @@
     k_in[2]  = new DigitalIn(kc, PullUp);
     k_in[3]  = new DigitalIn(kd, PullUp);
     k_in[4]  = new DigitalIn(ke, PullUp);
-    k_out[0] = new DigitalOut(kx);
-    k_out[1] = new DigitalOut(ky);
-    k_out[2] = new DigitalOut(kz);
-    k_out[3] = new DigitalOut(kw);
+    k_out[0] = new DigitalInOut(kx, PIN_OUTPUT, OpenDrain, 1);
+    k_out[1] = new DigitalInOut(ky, PIN_OUTPUT, OpenDrain, 1);
+    k_out[2] = new DigitalInOut(kz, PIN_OUTPUT, OpenDrain, 1);
+    k_out[3] = new DigitalInOut(kw, PIN_OUTPUT, OpenDrain, 1);
     key_mode    = 20;
     key_in_num  = 5;
     key_out_num = 4;
@@ -91,11 +91,11 @@
     k_in[2]  = new DigitalIn(kc, PullUp);
     k_in[3]  = new DigitalIn(kd, PullUp);
     k_in[4]  = new DigitalIn(ke, PullUp);
-    k_out[0] = new DigitalOut(kx);
-    k_out[1] = new DigitalOut(ky);
-    k_out[2] = new DigitalOut(kz);
-    k_out[3] = new DigitalOut(kw);
-    k_out[4] = new DigitalOut(kv);
+    k_out[0] = new DigitalInOut(kx, PIN_OUTPUT, OpenDrain, 1);
+    k_out[1] = new DigitalInOut(ky, PIN_OUTPUT, OpenDrain, 1);
+    k_out[2] = new DigitalInOut(kz, PIN_OUTPUT, OpenDrain, 1);
+    k_out[3] = new DigitalInOut(kw, PIN_OUTPUT, OpenDrain, 1);
+    k_out[4] = new DigitalInOut(kv, PIN_OUTPUT, OpenDrain, 1);
     key_mode    = 25;
     key_in_num  = 5;
     key_out_num = 5;
@@ -104,15 +104,6 @@
 
 void Keypad::initialize(void)
 {
-    *k_out[0] = 1;
-    *k_out[1] = 1;
-    *k_out[2] = 1;
-    if (key_mode > 12) {
-        *k_out[3] = 1;
-    }
-    if (key_mode > 20) {
-        *k_out[4] = 1;
-    }
     uint8_t j,i;
     for (j = 0; j < key_out_num; j++) {
         for(i = 0; i < key_in_num; i++) {
--- a/Keypad.h	Mon Apr 06 04:53:25 2020 +0000
+++ b/Keypad.h	Mon Apr 13 02:04:25 2020 +0000
@@ -8,7 +8,7 @@
  *  http://www7b.biglobe.ne.jp/~kenjia/
  *  https://os.mbed.com/users/kenjiArai/
  *      Created:    September 27th, 2017
- *      Revised:    April      6th, 2020
+ *      Revised:    April     13th, 2020
  */
 // ---- Merged below and added 4x5=20, 5x5=25 library --------------------------
 
@@ -143,9 +143,9 @@
 #define BF_SIZE     32
 #define NUM         5
 
-    DigitalIn   *k_in[NUM];
-    DigitalOut  *k_out[NUM];
-    Ticker      tk;
+    DigitalIn     *k_in[NUM];
+    DigitalInOut  *k_out[NUM];
+    Ticker        tk;
 
     // key control
     enum State {OFF_state, OFF_to_ON_transient, ON_state, ON_to_OFF_transient};