Created
April 27, 2021 10:16
-
-
Save mattura/1557e63f7cebddeacaa6267c9d37e9d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Capacitive touch gist for FeatherS2 either with an external | |
MPR121 capacitive touch board (adafruit_mpr121 library required) | |
Or using the ESP32 capacitive touch pads A2-A10 | |
''' | |
import time | |
import board | |
try: | |
import adafruit_mpr121 | |
i2c = board.I2C() | |
touch = adafruit_mpr121.MPR121(i2c) | |
except Exception as e: | |
print(f"{e}\nUsing ESP32 cap touch") | |
import touchio | |
#board.A2-A10 are touch caps: | |
pads = [board.A2, board.A3, board.A4, board.A5, board.A6, board.A7, board.A8, board.A9, board.A10] | |
touch = [] | |
for p in pads: | |
touch += [touchio.TouchIn(p)] | |
while True: | |
for i,t in enumerate(touch): | |
if touch[i].value: | |
print(f"{i}-{t} Touched!") | |
time.sleep(0.15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment