TTP229 16key touch keypad

Dependents:   TTP229_sample

TTP229 16key touch keypad.
/media/uploads/jk1lot/ttp229_MMK5gIi.jpg

This library support only 16key mode and active low mode
jamper set TP1=1(default) and TP2=0(jamper close).

pin connection

mbed                              TTP229
GPIO(InterruptIn) --------------- SDO
GPIO(DigitalOut)  --------------- SCL
             3.3V --------------- VCC
              GND --------------- GND

sample program is here.

アマゾンで購入したTTP229 を使った16キーのタッチキーパッドを使うためのライブラリです。
このボードは8keyモードにも設定できますが、このライブラリは16キーモード専用です
16キーモードに設定するには TP2を高抵抗でGNDに繋ぎます。私が入手したボードではジャンパ設定の3番をクローズにすればこの状態になります。
TP1で active low と active highの切替が出来ますが、このライブラリは active lowを想定していますので、TP1はデフォルトのまま(GNDには繋がない)にしてください。その他のジャンパは使用目的に応じて自由に設定して構いません。

詳しくはこちらをご覧ください。

Revision:
0:50226acdb872
Child:
1:c20148b5c68e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TTP229.h	Sat Jul 16 11:19:03 2016 +0000
@@ -0,0 +1,39 @@
+#ifndef TTP229_H
+#define TTP229_H
+#include "mbed.h"
+#include <bitset>
+
+/** 16key touch keypad\n
+ *  Only supported 16key and active low mode\n
+ *  jamper settng : TP1=1(jamper2=open):active low, TP2=0(jamper3=close):16key mode\n
+ */
+class TTP229 {
+public:
+    ///@param sdopin PinName that support DigitalIn and InterruptIn, connected to TTP229 SDO.
+    ///@param sclpin PinName that support DigitalOut, connected to TTP229 SCL.
+    TTP229(PinName sdopin, PinName sclpin);
+    ///set function that is called at change state of keypad
+    void attach(const FunctionPointer& fp) {callback=fp;}
+    ///get keypad status
+    bitset<16> getkeys() {return sw;}
+    ///same as getkeys()
+    operator bitset<16>() {return getkeys();}
+    ///get keypad status especially singlekey mode(TP3=1,TP4=1)
+    ///@return touched keypad number(1~16) or 0:no keypad touched
+    int onkey() {return swnum;}
+    ///Is number i(0~15) keypad touched?
+    bool ison(size_t i) {return getkeys()[i];}
+    ///same as ison()
+    bool operator[](size_t i) {return ison(i);}
+protected:
+    void interrupt();
+private:
+    DigitalIn sdo;
+    InterruptIn sdoInt;
+    DigitalOut scl;
+    FunctionPointer callback;
+    bitset<16> sw;
+    int swnum;
+};
+
+#endif
\ No newline at end of file