sample program for TTP229 16key touch keypad

Dependencies:   TTP229 mbed

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

Committer:
jk1lot
Date:
2016-07-16
Revision:
2:6d5546c95a7c
Parent:
0:4f0200333d59

File content as of revision 2:6d5546c95a7c:

#include "mbed.h"
#include "TTP229.h"

//DigitalOut myled(LED1);
//DigitalOut myled2(LED2);
//DigitalOut myled3(LED3);
BusOut myleds(LED1, LED2, LED3, LED4);

TTP229 touchpad(p22,p21);

string to_string(const bitset<16>& bs)
{
    return bs.to_string<char, std::char_traits<char>, std::allocator<char> >();
}

void ttp229int()
{
    printf("%16s\r\n",to_string(touchpad).c_str());
    //printf("%d\r\n",touchpad.onkey());
    //int sw=touchpad.getsingle();
    //if(sw!=0) myleds=sw%16;
}

int main()
{
    printf("Hello TTP229\r\n");
    touchpad.attach(&ttp229int);
    while(1) {
        for(int i=0; i<4; i++) {
            myleds[i]=touchpad[(i+1)*4-1];
        }
        wait(0.5);
    }
}