Simple tests

Ensure your device works with these simple tests.

examples/focaltouch_print_touches.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
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""
Example for getting touch data from an FT6206 or FT6236 capacitive
touch driver, over I2C
"""

import time
import busio
import board
import adafruit_focaltouch

# Create library object (named "ft") using a Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)

ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c, debug=False)

while True:
    # if the screen is being touched print the touches
    if ft.touched:
        print(ft.touches)
    else:
        print("no touch")

    time.sleep(0.15)
examples/focaltouch_paint_simpletest.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
37
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""
Simple painting demo that draws on an Adafruit capacitive touch shield with
ILI9341 display and FT6206 captouch driver
"""

import busio
import board
import digitalio
from adafruit_rgb_display import ili9341, color565
import adafruit_focaltouch

# Create library object using our Bus I2C & SPI port
i2c = busio.I2C(board.SCL, board.SDA)
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Adafruit Metro M0 + 2.8" Capacitive touch shield
cs_pin = digitalio.DigitalInOut(board.D10)
dc_pin = digitalio.DigitalInOut(board.D9)

# Initialize display
display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin)
# Fill with black!
display.fill(color565(0, 0, 0))

ft = adafruit_focaltouch.Adafruit_FocalTouch(i2c)

while True:
    if ft.touched:
        ts = ft.touches
        point = ts[0]  # the shield only supports one point!
        # perform transformation to get into display coordinate system!
        y = 320 - point["y"]
        x = 240 - point["x"]
        display.fill_rectangle(x - 2, y - 2, 4, 4, color565(255, 255, 255))