Skip to content

Instantly share code, notes, and snippets.

@mattura
Created April 27, 2021 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattura/1557e63f7cebddeacaa6267c9d37e9d9 to your computer and use it in GitHub Desktop.
Save mattura/1557e63f7cebddeacaa6267c9d37e9d9 to your computer and use it in GitHub Desktop.
'''
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