TOUCH Module API Manual#
Overview#
The touch module is based on RTT’s touch framework and supports single-point and multi-point capacitive touch screens as well as resistive touch screens.
API Introduction#
The TOUCH class is located under the machine module.
Example
from machine import TOUCH
# Instantiate TOUCH device 0
tp = TOUCH(0)
# Get TOUCH data
p = tp.read()
print(p)
# Print touch point coordinates
# print(p[0].x)
# print(p[0].y)
# print(p[0].event)
Constructor#
# when index is 0
touch = TOUCH(index, type = TOUCH.TYPE_CST328, rotate = -1)
# when index is 1
touch = TOUCH(index, type = TOUCH.TYPE_CST328, rotate = -1, range_x = -1, range_y = -1, i2c : I2C = None, slave_addr = None, rst : Pin = None, int : Pin = None)
Parameters
read Method#
TOUCH.read([count])
Get touch data.
Parameters
deinit Method#
TOUCH.deinit()
Release TOUCH resources.
Parameters
None
Return Value
None
TOUCH_INFO Class#
The TOUCH_INFO class is used to store information about touch points, which users can access through related read-only properties.
event: Event code, see Touch Events for details.track_id: Touch point ID, used for multi-point touch.width: Touch point width.x: x-coordinate of the touch point.y: y-coordinate of the touch point.timestamp: Touch point timestamp.
Constants#
Touch Events#
TOUCH.EVENT_NONE: No eventTOUCH.EVENT_UP: ReleasedTOUCH.EVENT_DOWN: PressedTOUCH.EVENT_MOVE: Moved
Coordinate Rotation#
TOUCH.ROTATE_0: No rotationTOUCH.ROTATE_90: Rotate coordinates 90 degreesTOUCH.ROTATE_180: Rotate coordinates 180 degreesTOUCH.ROTATE_270: Rotate coordinates 270 degreesTOUCH.ROTATE_SWAP_XY: Swap X and Y
Touch Types (compatibility only, all values are 0)#
TOUCH.TYPE_CST226SETOUCH.TYPE_CST328TOUCH.TYPE_GT911
