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.
Dependents: Keypad_input_OS2 Keypad_input
Diff: Keypad.h
- Revision:
- 0:b7249629f337
- Child:
- 1:ed0ad90ad734
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Keypad.h Sat Sep 30 23:17:15 2017 +0000
@@ -0,0 +1,83 @@
+/*
+ * Mbed Library / Akizuki AE-KIT45-KEYPAD4X3
+ * http://akizukidenshi.com/catalog/g/gK-12229/
+ *
+ * Copyright (c) 2017 Kenji Arai / JH1PJL
+ * http://www.page.sannet.ne.jp/kenjia/index.html
+ * http://mbed.org/users/kenjiArai/
+ * Created: September 27th, 2017
+ * Revised: October 1st, 2017
+ */
+
+#ifndef KEYPAD_H
+#define KEYPAD_H
+
+#include "mbed.h"
+
+#define CHNG_CNT 3
+
+/**
+ * @code
+ * #include "mbed.h"
+ * #include "Keypad.h"
+ *
+ * // every 2ms runs 6uS for key detection (CPU occupancy is 0.3%)
+ * // output port X Y Z
+ * // Input A * 0 #
+ * // Input B 7 8 9
+ * // Input C 4 5 6
+ * // Input D 1 2 3
+ * // X Y Z A B C D OUT(XYZ), IN(ABCD)
+ * Keypad key(D10, D9, D8, D7, D6, D5, D4);
+ *
+ * // define key number at main routine
+ * char *const key_table = "?*7410852#963"; // key_table[0]=? is not used!
+ *
+ * int main() {
+ * uint32_t key_num;
+ * while(true) {
+ * while ((key_num = key.read()) != 0){
+ * printf("%c\r\n", *(key_table + key_num));
+ * }
+ * wait(1.0);
+ * }
+ * }
+ * @endcode
+ */
+
+class Keypad {
+public:
+ /** 4x3 keypad interface:
+ * @param key input port A,B,C,D
+ * @param key output(scan) port X,Y,Z
+ */
+ Keypad(PinName kx, PinName ky, PinName kz,
+ PinName ka, PinName kb, PinName kc, PinName kd);
+
+ /** Read key data into buffer
+ * @param none
+ * @return key number 1 to 12 (0 = no key action)
+ */
+ uint8_t read(void);
+
+protected:
+ DigitalIn *k_in[4];
+ DigitalOut *k_out[3];
+ Ticker tk;
+
+ // key control
+ enum State {Off_state, Off_to_on_transient, On_state, On_to_off_transient};
+ volatile State key_state[3][4];
+ volatile int8_t key_transent_cntr[3][4];
+ void key_scan(void);
+
+ // buffer control
+ uint8_t read_addr;
+ uint8_t write_addr;
+ uint8_t buf[32];
+ void bf_put (char dat);
+ int8_t bf_get (void);
+
+};
+
+#endif // KEYPAD_H