![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sample program for TTP229 16key touch keypad
sample program for TTP229 library
pin connection
PC mbed LPC1768 TTP229 P22 ----------- SDO P21 ----------- SCL 3.3V ----------- VCC GND ----------- GND USB ------ USB(UART)
main.cpp@2:6d5546c95a7c, 2016-07-16 (annotated)
- Committer:
- jk1lot
- Date:
- Sat Jul 16 17:51:09 2016 +0000
- Revision:
- 2:6d5546c95a7c
- Parent:
- 0:4f0200333d59
TTP229 library update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jk1lot | 0:4f0200333d59 | 1 | #include "mbed.h" |
jk1lot | 0:4f0200333d59 | 2 | #include "TTP229.h" |
jk1lot | 0:4f0200333d59 | 3 | |
jk1lot | 0:4f0200333d59 | 4 | //DigitalOut myled(LED1); |
jk1lot | 0:4f0200333d59 | 5 | //DigitalOut myled2(LED2); |
jk1lot | 0:4f0200333d59 | 6 | //DigitalOut myled3(LED3); |
jk1lot | 0:4f0200333d59 | 7 | BusOut myleds(LED1, LED2, LED3, LED4); |
jk1lot | 0:4f0200333d59 | 8 | |
jk1lot | 0:4f0200333d59 | 9 | TTP229 touchpad(p22,p21); |
jk1lot | 0:4f0200333d59 | 10 | |
jk1lot | 0:4f0200333d59 | 11 | string to_string(const bitset<16>& bs) |
jk1lot | 0:4f0200333d59 | 12 | { |
jk1lot | 0:4f0200333d59 | 13 | return bs.to_string<char, std::char_traits<char>, std::allocator<char> >(); |
jk1lot | 0:4f0200333d59 | 14 | } |
jk1lot | 0:4f0200333d59 | 15 | |
jk1lot | 0:4f0200333d59 | 16 | void ttp229int() |
jk1lot | 0:4f0200333d59 | 17 | { |
jk1lot | 0:4f0200333d59 | 18 | printf("%16s\r\n",to_string(touchpad).c_str()); |
jk1lot | 0:4f0200333d59 | 19 | //printf("%d\r\n",touchpad.onkey()); |
jk1lot | 0:4f0200333d59 | 20 | //int sw=touchpad.getsingle(); |
jk1lot | 0:4f0200333d59 | 21 | //if(sw!=0) myleds=sw%16; |
jk1lot | 0:4f0200333d59 | 22 | } |
jk1lot | 0:4f0200333d59 | 23 | |
jk1lot | 0:4f0200333d59 | 24 | int main() |
jk1lot | 0:4f0200333d59 | 25 | { |
jk1lot | 0:4f0200333d59 | 26 | printf("Hello TTP229\r\n"); |
jk1lot | 0:4f0200333d59 | 27 | touchpad.attach(&ttp229int); |
jk1lot | 0:4f0200333d59 | 28 | while(1) { |
jk1lot | 0:4f0200333d59 | 29 | for(int i=0; i<4; i++) { |
jk1lot | 0:4f0200333d59 | 30 | myleds[i]=touchpad[(i+1)*4-1]; |
jk1lot | 0:4f0200333d59 | 31 | } |
jk1lot | 0:4f0200333d59 | 32 | wait(0.5); |
jk1lot | 0:4f0200333d59 | 33 | } |
jk1lot | 0:4f0200333d59 | 34 | } |