Giter VIP home page Giter VIP logo

ttp229's Introduction

TTP229 Arduino Library

An Arduino library for TTP229 module for controlling a 16 capacitive touch keys.

Tested with the Robotdyn 16 Keys I2C Capacitive Touch TTP229 Module Robotdyn Capacitive Touch Disk Pad.

Connection

  • Uno:

    • SDA <-> A4 (SDA)
    • SCL <-> A5 (SCL)
  • Mega:

    • SDA <-> 20 (SDA)
    • SCL <-> 21 (SCL)
  • Leo:

    • SDA <-> 2 (SDA)
    • SCL <-> 3 (SCL)
  • ESP32-WROOM-32:

    • SDA <-> GPIO 21 (SDA)
    • SCL <-> GPIO 22 (SCL)

Methods:

  • uint16_t readKeys() - Read data from TTP229 and return states of 16 keys in bitmap representation. This method should call before other methods. Put it into loop function.

  • int getKey() - Return number of pressed key or return -1 if no one key is pressed.

  • bool isKeyPress(byte key) - Return true if key is pressed.

  • bool isKeyDown(byte key) - Return true if key is down.

  • bool isKeyUp(byte key) - Return true if key is up.

Example

#include <Wire.h>
#include <TTP229.h>

TTP229 ttp229;

void setup()
{
    Wire.begin();
    Serial.begin(9600);
}

void loop()
{
    ttp229.readKeys();

    Serial.print("Key states: ");
    for (int i = 0; i < 16; ++i) {
        if (ttp229.isKeyPress(i)) {
            Serial.print("1 ");
        } else {
            Serial.print("0 ");
        }
    }

    int key = ttp229.getKey();
    Serial.print("Pressed key: ");
    Serial.print(key);

    Serial.print("   ");
    if (ttp229.isKeyDown(0)) {
        Serial.print("Key 0 is down");
    } else if (ttp229.isKeyUp(0)) {
        Serial.print("Key 0 is up");
    }

    Serial.println();
    delay(500);
}

License

Copyright (c) 2019 Alexander Kiryanenko. Licensed under the MIT license.

ttp229's People

Contributors

6r1d avatar kiryanenko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.