Giter Club home page Giter Club logo

micropython-cap1296's Introduction

CAP1296

Micropython module for Microchip CAP1296 I2C touch controller. You should have a working knowledge of how the CAP1296 works, please check out its datasheet.

Examples

I'm using a NodeMCU with Micropython (FW 1.9.3). A minimal working example starts with this setup:

# SETUP
import machine
import cap1296

# NodeMCU I2C interface
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4), freq=400000)
tc = cap1296.CAP1296(i2c)  # touch controller

Then we can get the status of the CAP's sensor input register using the read_keys function like this.

# No multitouch, print keys status as a byte
keys_now, keys_before = 0, 0
while True:
    keys_now, keys_before = tc.read_keys(), keys_now

    if keys_now != keys_before:  # keys state changed
        print(keys_now)

This prints a byte of the keys status each time the input changes (note that the output might be different than below if the byte is printable).

b'\x00'  # no key pressed
b'\x01'  # key 0 pressed
b'\x00'
b'\x02'  # key 1 pressed
b'\x00'
b'\x04'  # key 2 pressed
...

If you want multitouch and a list of all currently pressed keys, try this:

# Multitouch enabled, print list of pressed keys
tc.enable_multitouch(True)

# same as in the example above
keys_now, keys_before = 0, 0
while True:
    keys_now, keys_before = tc.read_keys(as_list=True), keys_now

    if keys_now != keys_before:  # user input occured
        print(keys_now)

This gives you:

[]  # no key pressed
[0]  # key 0 pressed
[0, 1]  # key 0 and 1 pressed
[]  # no key pressed
[1]  # key 1 pressed
[0, 1, 2, 3, 4]  # keys 0 to 4 pressed

Todo

  • the enable_signal_guard function is untested yet

micropython-cap1296's People

Contributors

wese3112 avatar

Watchers

 avatar  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.