-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
36 lines (29 loc) · 1.2 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# be sure to run first:
# sudo pip3 install adafruit-circuitpython-mpr121 --break-system-packages
# sudo raspi-config nonint do_i2c 0
# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
# SPDX-License-Identifier: MIT
# Simple test of the MPR121 capacitive touch sensor library.
# Will print out a message when any of the 12 capacitive touch inputs of the
# board are touched. Open the serial REPL after running to see the output.
# Author: Tony DiCola
import time
import board
import busio
# Import MPR121 module.
import adafruit_mpr121
# Create I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Create MPR121 object.
mpr121 = adafruit_mpr121.MPR121(i2c)
# Note you can optionally change the address of the device:
# mpr121 = adafruit_mpr121.MPR121(i2c, address=0x91)
# Loop forever testing each input and printing when they're touched.
while True:
# Loop through all 12 inputs (0-11).
for i in range(12):
# Call is_touched and pass it then number of the input. If it's touched
# it will return True, otherwise it will return False.
if mpr121[i].value:
print("Input {} touched!".format(i))
time.sleep(0.25) # Small delay to keep from spamming output messages.