Skip to content

Instantly share code, notes, and snippets.

@joeycastillo
Created January 24, 2020 21:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeycastillo/4b656ba570aa9b843852fd79f05ae38a to your computer and use it in GitHub Desktop.
Save joeycastillo/4b656ba570aa9b843852fd79f05ae38a to your computer and use it in GitHub Desktop.
Capacitive Touch Matrix Test
"""
Test script for CAPT-B1-02 Capacitive Touch Matrix FeatherWing
Board files: https://github.com/joeycastillo/Feather-Projects/tree/master/Experiments/Cap%20Touch%20Experiments
Also uses an Adafruit 16x8 LED matrix:
https://www.adafruit.com/product/2037
"""
import board
import touchio
import busio as io
import adafruit_ht16k33.matrix
i2c = io.I2C(board.SCL, board.SDA)
matrix = adafruit_ht16k33.matrix.Matrix16x8(i2c)
matrix.auto_write = False
X0 = touchio.TouchIn(board.A4)
X1 = touchio.TouchIn(board.A3)
X2 = touchio.TouchIn(board.A2)
X3 = touchio.TouchIn(board.A1)
X4 = touchio.TouchIn(board.D12)
X5 = touchio.TouchIn(board.D11)
X6 = touchio.TouchIn(board.D9)
X7 = touchio.TouchIn(board.A5)
X8 = touchio.TouchIn(board.RX)
X9 = touchio.TouchIn(board.MISO)
Y0 = touchio.TouchIn(board.D5)
Y1 = touchio.TouchIn(board.D6)
Y2 = touchio.TouchIn(board.D10)
Y3 = touchio.TouchIn(board.TX)
def set_pixel(x, y):
if y > 7:
# push pixel to second matrix
y = y - 8
x = x + 8
matrix[x, y] = 1
def print_status(col, row):
matrix.fill(0)
for y in range(0, 4):
for x in range(0, 10):
if y == row and x == col:
pass
elif y == row:
set_pixel(y + 2, x + 3)
elif x == col:
set_pixel(y + 2, x + 3)
matrix.show()
while True:
row = None
if Y0.value:
row = 0
if Y1.value:
row = 1
if Y2.value:
row = 2
if Y3.value:
row = 3
if row is not None:
if X0.value:
print_status(0, row)
if X1.value:
print_status(1, row)
if X2.value:
print_status(2, row)
if X3.value:
print_status(3, row)
if X4.value:
print_status(4, row)
if X5.value:
print_status(5, row)
if X6.value:
print_status(6, row)
if X7.value:
print_status(7, row)
if X8.value:
print_status(8, row)
if X9.value:
print_status(9, row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment